[][src]Struct genco::prelude::rust::Type

pub struct Type { /* fields omitted */ }

An imported name in Rust.

Implementations

impl Type[src]

pub fn alias<A: Into<ItemStr>>(self, alias: A) -> Self[src]

Alias the given type as it's imported.

Examples

use genco::prelude::*;

let ty = rust::imported("std::fmt", "Debug").alias("FmtDebug");

let toks = quote!(#ty);

assert_eq!(
    vec![
        "use std::fmt::Debug as FmtDebug;",
        "",
        "FmtDebug",
    ],
    toks.to_file_vec().unwrap()
);

pub fn module_alias<A: Into<ItemStr>>(self, alias: A) -> Type[src]

Alias the module being imported.

This also implies that the import is [prefixed()].

Examples

use genco::prelude::*;

let ty = rust::imported("std::fmt", "Debug").module_alias("other");

let toks = quote!(#ty);

assert_eq!(
    vec![
        "use std::fmt as other;",
        "",
        "other::Debug",
    ],
    toks.to_file_vec().unwrap()
);

pub fn prefixed(self) -> Type[src]

Prefix any use of this type with the corresponding module.

So importing std::fmt::Debug will cause the module to be referenced as fmt::Debug instead of Debug.

This is implied if [module_alias()] is used.

Examples

use genco::prelude::*;

let ty = rust::imported("std::fmt", "Debug").prefixed();

let toks = quote!(#ty);

assert_eq!(
    vec![
        "use std::fmt;",
        "",
        "fmt::Debug",
    ],
    toks.to_file_vec().unwrap()
);

pub fn with_arguments(self, args: impl Args) -> Type[src]

Add generic arguments to the type.

Examples

use genco::prelude::*;

let ty = rust::imported("std::collections", "HashMap")
    .with_arguments((rust::local("u32"), rust::local("u32")));

let toks = quote!(#ty);

assert_eq!(
    vec![
        "use std::collections::HashMap;",
        "",
        "HashMap<u32, u32>",
    ],
    toks.to_file_vec().unwrap()
);
use genco::prelude::*;

let dbg = rust::imported("std::collections", "HashMap")
    .prefixed()
    .with_arguments((rust::local("T"), rust::local("U")));

let toks = quote!(#dbg);

assert_eq!(
    vec![
       "use std::collections;",
       "",
       "collections::HashMap<T, U>",
    ],
    toks.to_file_vec().unwrap()
);

pub fn reference<R: Into<Reference>>(self, reference: R) -> Self[src]

Convert into a reference &<type> type.

pub fn into_dyn(self) -> Self[src]

Convert into a dynamic dyn <type> type.

Trait Implementations

impl Clone for Type[src]

impl Debug for Type[src]

impl Eq for Type[src]

impl FormatTokens<Rust> for Type[src]

impl<'a> FormatTokens<Rust> for &'a Type[src]

impl<'a> From<&'a Type> for LangBox<Rust>[src]

impl From<Type> for LangBox<Rust>[src]

impl Hash for Type[src]

impl LangItem<Rust> for Type[src]

impl Ord for Type[src]

impl PartialEq<Type> for Type[src]

impl PartialOrd<Type> for Type[src]

impl StructuralEq for Type[src]

impl StructuralPartialEq for Type[src]

Auto Trait Implementations

impl RefUnwindSafe for Type

impl Send for Type

impl Sync for Type

impl Unpin for Type

impl UnwindSafe for Type

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.