Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  automatic_bounds.rs

  Sprache: Rust
 

use darling::{FromDeriveInput, FromMeta};

#[derive(FromMeta, PartialEq, Eq, Debug)]
enum Volume {
    Whisper,
    Talk,
    Shout,
}

/// A more complex example showing the ability to skip at a field or struct
/// level while still tracking which type parameters need to be bounded.
/// This can be seen by expanding this example using `cargo expand`.
#[derive(FromMeta)]
#[allow(dead_code)]
enum Emphasis<T> {
    Constant(Volume),
    Variable(darling::util::PathList),
    #[darling(skip)]
    PerPhoneme(Option<T>),
    Strided {
        #[darling(skip)]
        step: Vec<T>,
        #[darling(multiple)]
        volume: Vec<Volume>,
    },
}

#[derive(FromDeriveInput)]
#[darling(attributes(speak))]
struct SpeakingOptions<T, U> {
    max_volume: U,
    #[darling(skip, default)]
    additional_data: Vec<T>,
}

#[derive(Default)]
struct Phoneme {
    #[allow(dead_code)]
    first: String,
}

// This is probably the holy grail for `darling`'s own internal use-case:
// Auto-apply `Default` bound to skipped *field* types in `where` clause.
impl<T, U> Default for SpeakingOptions<T, U>
where
    Vec<T>: Default,
    U: Default,
{
    fn default() -> Self {
        Self {
            max_volume: Default::default(),
            additional_data: Default::default(),
        }
    }
}

fn main() {
    let derive_input = syn::parse_str(
        r#"
        #[derive(Speak)]
        #[speak(max_volume = "shout")]
        enum HtmlElement {
            Div(String)
        }
    "#,
    )
    .unwrap();

    let parsed: SpeakingOptions<Phoneme, Volume> =
        FromDeriveInput::from_derive_input(&derive_input).unwrap();
    assert_eq!(parsed.max_volume, Volume::Shout);
    assert_eq!(parsed.additional_data.len(), 0);
}

Messung V0.5 in Prozent
C=83 H=97 G=90

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002