[][src]Trait genco::lang::csharp::AsAny

pub trait AsAny where
    Self: LangItem<Csharp>, 
{ fn as_any(&self) -> Any; }

Language-specific conversion trait implemented by all language items.

Required methods

fn as_any(&self) -> Any

Coerce trait into an enum that can be used for type-specific operations.

Examples

use genco::fmt;

genco::impl_lang! {
    MyLang {
        type Config = ();
        type Import = dyn AsAny;
        type Format = ();
    }

    Import {
        fn format(&self, fmt: &mut fmt::Formatter<'_>, config: &(), format: &()) -> fmt::Result {
            use std::fmt::Write as _;

            write!(fmt, "{}", self.0)
        }

        fn as_import(&self) -> Option<&dyn AsAny> {
            Some(self)
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct Import(usize);

use genco::{quote, Tokens};

let tokens: Tokens<MyLang> = quote! {
    #(Import(0))
    #(Import(1))
};

/// Find and compare all imports.
assert_eq!(2, tokens.walk_imports().count());

for (i, import) in tokens.walk_imports().enumerate() {
    assert_eq!(Any::Import(&Import(i)), import.as_any());
}

assert_eq!{
    vec![
        "0",
        "1",
    ],
    tokens.to_file_vec()?
};
Loading content...

Implementors

impl AsAny for Import[src]

Loading content...