pub enum RustType {
Generic {
id: TypeName,
parameters: Vec<RustType>,
},
Special(SpecialRustType),
Simple {
id: TypeName,
},
}Expand description
A named Rust type.
Variants§
Generic
A type with generic parameters. Consists of a type ID + parameters that come after in angled brackets. Examples include:
SomeStruct<String>SomeEnum<u32>SomeTypeAlias<(), &str>However, there are some generic types that are considered to be special. These includeVec<T>HashMap<K, V>, andOption<T>, which are part ofSpecialRustTypeinstead ofRustType::Generic.
If a generic type is type-mapped via typeshare.toml, the generic parameters will be dropped automatically.
Special(SpecialRustType)
A type that requires a special transformation to its respective language. This includes many core types, like string types, basic container types, numbers, and other primitives.
Simple
A type with no generic parameters that is not considered a special type. This includes
all user-generated types and some types from the standard library or third-party crates.
However, these types can still be transformed as part of the type-map in typeshare.toml.
Implementations§
Source§impl RustType
impl RustType
Sourcepub fn contains_type(&self, ty: &TypeName) -> bool
pub fn contains_type(&self, ty: &TypeName) -> bool
Check if a type contains a type with an ID that matches ty.
For example, Box<String> contains the types Box and String. Similarly,
Vec<Option<HashMap<String, Url>>> contains the types Vec, Option, HashMap,
String, and Url.
Sourcepub fn is_optional(&self) -> bool
pub fn is_optional(&self) -> bool
Check if the type is Option<T>
Sourcepub fn is_double_optional(&self) -> bool
pub fn is_double_optional(&self) -> bool
Check if the type is Option<Option<T>>
Sourcepub fn is_hash_map(&self) -> bool
pub fn is_hash_map(&self) -> bool
Check if the type is HashMap<K, V>
Sourcepub fn parameters(&self) -> Box<dyn Iterator<Item = &Self> + '_>
pub fn parameters(&self) -> Box<dyn Iterator<Item = &Self> + '_>
Get the generic parameters for this type. Returns an empty iterator if there are none.
For example, Vec<String>’s generic parameters would be [String].
Meanwhile, HashMap<i64, u32>’s generic parameters would be [i64, u32].
Finally, a type like String would have no generic parameters.
Trait Implementations§
impl Eq for RustType
impl StructuralPartialEq for RustType
Auto Trait Implementations§
impl Freeze for RustType
impl RefUnwindSafe for RustType
impl Send for RustType
impl Sync for RustType
impl Unpin for RustType
impl UnwindSafe for RustType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more