pub struct FieldMut<'a> { /* private fields */ }Expand description
A mutable struct field reference.
A FieldMut is a proxy for mutable operations on a struct’s field.
Values of this type are created by FieldAccess::field_mut.
Implementations§
Source§impl<'a> FieldMut<'a>
impl<'a> FieldMut<'a>
Sourcepub fn get_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn get_mut<T: Any>(&mut self) -> Option<&mut T>
Obtains a mutable reference to the value of type T.
Returns Some(_) if field’s value is of type T, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let mut foo = Foo { a: 1 };
let mut field = foo.field_mut("a").unwrap();
if let Some(field) = field.get_mut::<u8>() {
*field = 42;
}
assert_eq!(field.as_u8(), Some(42u8));
assert_eq!(field.get_mut::<&str>(), None);Sourcepub fn as_any_mut(&mut self) -> &mut dyn Any
pub fn as_any_mut(&mut self) -> &mut dyn Any
Obtains a mutable reference to the value as &mut dyn Any.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let mut foo = Foo { a: 42 };
let mut field = foo.field_mut("a").unwrap();
let any = field.as_any_mut();
if let Some(value) = any.downcast_mut::<u8>() {
*value = 42;
}
assert_eq!(foo.a, 42);Sourcepub fn set<T: Any>(&mut self, value: T) -> bool
pub fn set<T: Any>(&mut self, value: T) -> bool
Sets the value of the field.
Returns true if it was possible to replace the field’s value with a value of type T,
false otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let mut foo = Foo { a: 1 };
let mut field = foo.field_mut("a").unwrap();
assert!(field.set(42u8));
assert_eq!(foo.a, 42);Sourcepub fn replace<T: Any>(&mut self, value: T) -> Option<T>
pub fn replace<T: Any>(&mut self, value: T) -> Option<T>
Replaces the value of the field, returning the previous value.
Returns Some(old_value) if it was possible to replace the field’s value with a value of
type T, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let mut foo = Foo { a: 1 };
let mut field = foo.field_mut("a").unwrap();
assert_eq!(field.replace(42u8), Some(1));
assert_eq!(foo.a, 42);Sourcepub fn swap<T: Any>(&mut self, value: &mut T) -> bool
pub fn swap<T: Any>(&mut self, value: &mut T) -> bool
Swaps the value of the field and another mutable location.
Returns true if it was possible to replace the field’s value with a value of type T,
false otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let mut foo = Foo { a: 1 };
let mut value = 2u8;
let mut field = foo.field_mut("a").unwrap();
assert!(field.swap(&mut value));
assert_eq!(foo.a, 2);
assert_eq!(value, 1);Sourcepub fn take<T: Any + Default>(&mut self) -> Option<T>
pub fn take<T: Any + Default>(&mut self) -> Option<T>
Takes the value of the field, replacing it with its default value.
Returns Some(_) if it was possible to replace the field’s value with the default value of
type T, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let mut foo = Foo { a: 42 };
let mut field = foo.field_mut("a").unwrap();
assert_eq!(field.take(), Some(42u8));
assert_eq!(foo.a, 0);Sourcepub fn as_vec_mut<T: Any>(&mut self) -> Option<&mut Vec<T>>
pub fn as_vec_mut<T: Any>(&mut self) -> Option<&mut Vec<T>>
Returns a mutable reference to the value as &mut Vec<T>.
Returns Some(_) if the field’s value is of type Vec<T>, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: Vec<u8>
}
let mut foo = Foo { a: vec![1, 2, 3] };
let mut field = foo.field_mut("a").unwrap();
if let Some(vec) = field.as_vec_mut::<u8>() {
vec.push(4);
}
assert_eq!(foo.a, vec![1, 2, 3, 4]);Sourcepub fn as_string_mut(&mut self) -> Option<&mut String>
pub fn as_string_mut(&mut self) -> Option<&mut String>
Returns a mutable reference to the field value as &mut String.
Returns Some(_) if the field’s value is of type String, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: String,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_string_mut() {
*value = String::from("bar");
}
assert_eq!(foo.a, String::from("bar"));Sourcepub fn as_bool_mut(&mut self) -> Option<&mut bool>
pub fn as_bool_mut(&mut self) -> Option<&mut bool>
Returns a mutable reference to the field value as &mut bool.
Returns Some(_) if the field’s value is of type bool, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: bool,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_bool_mut() {
*value = true;
}
assert_eq!(foo.a, true);Sourcepub fn as_u8_mut(&mut self) -> Option<&mut u8>
pub fn as_u8_mut(&mut self) -> Option<&mut u8>
Returns a mutable reference to the field value as &mut u8.
Returns Some(_) if the field’s value is of type u8, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u8,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_u8_mut() {
*value = < u8 > :: MAX;
}
assert_eq!(foo.a, < u8 > :: MAX);Sourcepub fn as_u16_mut(&mut self) -> Option<&mut u16>
pub fn as_u16_mut(&mut self) -> Option<&mut u16>
Returns a mutable reference to the field value as &mut u16.
Returns Some(_) if the field’s value is of type u16, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u16,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_u16_mut() {
*value = < u16 > :: MAX;
}
assert_eq!(foo.a, < u16 > :: MAX);Sourcepub fn as_u32_mut(&mut self) -> Option<&mut u32>
pub fn as_u32_mut(&mut self) -> Option<&mut u32>
Returns a mutable reference to the field value as &mut u32.
Returns Some(_) if the field’s value is of type u32, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u32,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_u32_mut() {
*value = < u32 > :: MAX;
}
assert_eq!(foo.a, < u32 > :: MAX);Sourcepub fn as_u64_mut(&mut self) -> Option<&mut u64>
pub fn as_u64_mut(&mut self) -> Option<&mut u64>
Returns a mutable reference to the field value as &mut u64.
Returns Some(_) if the field’s value is of type u64, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u64,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_u64_mut() {
*value = < u64 > :: MAX;
}
assert_eq!(foo.a, < u64 > :: MAX);Sourcepub fn as_u128_mut(&mut self) -> Option<&mut u128>
pub fn as_u128_mut(&mut self) -> Option<&mut u128>
Returns a mutable reference to the field value as &mut u128.
Returns Some(_) if the field’s value is of type u128, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u128,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_u128_mut() {
*value = < u128 > :: MAX;
}
assert_eq!(foo.a, < u128 > :: MAX);Sourcepub fn as_usize_mut(&mut self) -> Option<&mut usize>
pub fn as_usize_mut(&mut self) -> Option<&mut usize>
Returns a mutable reference to the field value as &mut usize.
Returns Some(_) if the field’s value is of type usize, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: usize,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_usize_mut() {
*value = < usize > :: MAX;
}
assert_eq!(foo.a, < usize > :: MAX);Sourcepub fn as_i8_mut(&mut self) -> Option<&mut i8>
pub fn as_i8_mut(&mut self) -> Option<&mut i8>
Returns a mutable reference to the field value as &mut i8.
Returns Some(_) if the field’s value is of type i8, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i8,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_i8_mut() {
*value = < i8 > :: MAX;
}
assert_eq!(foo.a, < i8 > :: MAX);Sourcepub fn as_i16_mut(&mut self) -> Option<&mut i16>
pub fn as_i16_mut(&mut self) -> Option<&mut i16>
Returns a mutable reference to the field value as &mut i16.
Returns Some(_) if the field’s value is of type i16, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i16,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_i16_mut() {
*value = < i16 > :: MAX;
}
assert_eq!(foo.a, < i16 > :: MAX);Sourcepub fn as_i32_mut(&mut self) -> Option<&mut i32>
pub fn as_i32_mut(&mut self) -> Option<&mut i32>
Returns a mutable reference to the field value as &mut i32.
Returns Some(_) if the field’s value is of type i32, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i32,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_i32_mut() {
*value = < i32 > :: MAX;
}
assert_eq!(foo.a, < i32 > :: MAX);Sourcepub fn as_i64_mut(&mut self) -> Option<&mut i64>
pub fn as_i64_mut(&mut self) -> Option<&mut i64>
Returns a mutable reference to the field value as &mut i64.
Returns Some(_) if the field’s value is of type i64, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i64,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_i64_mut() {
*value = < i64 > :: MAX;
}
assert_eq!(foo.a, < i64 > :: MAX);Sourcepub fn as_i128_mut(&mut self) -> Option<&mut i128>
pub fn as_i128_mut(&mut self) -> Option<&mut i128>
Returns a mutable reference to the field value as &mut i128.
Returns Some(_) if the field’s value is of type i128, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i128,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_i128_mut() {
*value = < i128 > :: MAX;
}
assert_eq!(foo.a, < i128 > :: MAX);Sourcepub fn as_isize_mut(&mut self) -> Option<&mut isize>
pub fn as_isize_mut(&mut self) -> Option<&mut isize>
Returns a mutable reference to the field value as &mut isize.
Returns Some(_) if the field’s value is of type isize, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: isize,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_isize_mut() {
*value = < isize > :: MAX;
}
assert_eq!(foo.a, < isize > :: MAX);Sourcepub fn as_f32_mut(&mut self) -> Option<&mut f32>
pub fn as_f32_mut(&mut self) -> Option<&mut f32>
Returns a mutable reference to the field value as &mut f32.
Returns Some(_) if the field’s value is of type f32, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: f32,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_f32_mut() {
*value = < f32 > :: MAX;
}
assert_eq!(foo.a, < f32 > :: MAX);Sourcepub fn as_f64_mut(&mut self) -> Option<&mut f64>
pub fn as_f64_mut(&mut self) -> Option<&mut f64>
Returns a mutable reference to the field value as &mut f64.
Returns Some(_) if the field’s value is of type f64, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: f64,
}
let mut foo = Foo::default();
let mut field = foo.field_mut("a").unwrap();
if let Some(value) = field.as_f64_mut() {
*value = < f64 > :: MAX;
}
assert_eq!(foo.a, < f64 > :: MAX);Methods from Deref<Target = Field<'a>>§
Sourcepub fn is<T: Any>(&self) -> bool
pub fn is<T: Any>(&self) -> bool
Returns true if the field is of type T.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let foo = Foo { a: 1 };
let field = foo.field("a").unwrap();
assert!(field.is::<u8>());
assert!(!field.is::<&str>());Sourcepub fn type_id(&self) -> TypeId
pub fn type_id(&self) -> TypeId
Gets the TypeId of the field’s value.
§Example
use core::any::TypeId;
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let foo = Foo { a: 1 };
let field = foo.field("a").unwrap();
assert_eq!(field.type_id(), TypeId::of::<u8>());Sourcepub fn get<T: Any>(&self) -> Option<&T>
pub fn get<T: Any>(&self) -> Option<&T>
Obtains an immutable reference to the value of type T.
Returns Some(_) if field’s value is of type T, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let foo = Foo { a: 42 };
let field = foo.field("a").unwrap();
assert_eq!(field.get::<u8>(), Some(&42u8));
assert_eq!(field.get::<&str>(), None);Sourcepub fn as_any(&self) -> &dyn Any
pub fn as_any(&self) -> &dyn Any
Obtains an immutable reference to the value as &dyn Any.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8
}
let foo = Foo { a: 42 };
let field = foo.field("a").unwrap();
let any = field.as_any();
assert_eq!(any.downcast_ref::<u8>(), Some(&42u8));Sourcepub fn is_slice<T: Any>(&self) -> bool
pub fn is_slice<T: Any>(&self) -> bool
Returns true if the field value is of type &[T].
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: &'static [u8]
}
let foo = Foo { a: &[1, 2, 3] };
let field = foo.field("a").unwrap();
assert!(field.is_slice::<u8>());Sourcepub fn as_slice<T: Any>(&self) -> Option<&[T]>
pub fn as_slice<T: Any>(&self) -> Option<&[T]>
Obtain an immutable reference to the value as &[T].
Returns Some(_) if .is_slice::<T>() or
.is_vec::<T>() would return true, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: Vec<u8>
}
let foo = Foo { a: vec![1, 2, 3] };
let field = foo.field("a").unwrap();
assert_eq!(field.as_slice(), Some(&[1u8, 2, 3][..]));Sourcepub fn is_vec<T: Any>(&self) -> bool
pub fn is_vec<T: Any>(&self) -> bool
Returns true if the field value is of type Vec<T>.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: Vec<u8>
}
let foo = Foo { a: vec![1, 2, 3] };
let field = foo.field("a").unwrap();
assert!(field.is_vec::<u8>());
assert!(!field.is_vec::<u16>());Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true if the field value is of type String.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: String,
}
let foo = Foo { a: String::from("bar") };
let field = foo.field("a").unwrap();
assert!(field.is_string());
assert!(!field.is_str());Sourcepub fn is_str(&self) -> bool
pub fn is_str(&self) -> bool
Returns true if the field value is of type &str.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: &'static str,
}
let foo = Foo { a: "bar" };
let field = foo.field("a").unwrap();
assert!(field.is_str());Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Obtain an immutable reference to the value as &str.
Returns Some(_) if .is_str() or .is_string() would
return true, None otherwise.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: String
}
let foo = Foo { a: String::from("bar") };
let field = foo.field("a").unwrap();
assert_eq!(field.as_str(), Some("bar"));Sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&self) -> bool
Returns true if the field value is of type bool.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: bool,
}
let foo = Foo { a: bool::default() };
let field = foo.field("a").unwrap();
assert!(field.is_bool());
assert!(!field.is::<&bool>());Sourcepub fn is_u8(&self) -> bool
pub fn is_u8(&self) -> bool
Returns true if the field value is of type u8.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u8,
}
let foo = Foo { a: u8::default() };
let field = foo.field("a").unwrap();
assert!(field.is_u8());
assert!(!field.is::<&u8>());Sourcepub fn is_u16(&self) -> bool
pub fn is_u16(&self) -> bool
Returns true if the field value is of type u16.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u16,
}
let foo = Foo { a: u16::default() };
let field = foo.field("a").unwrap();
assert!(field.is_u16());
assert!(!field.is::<&u16>());Sourcepub fn is_u32(&self) -> bool
pub fn is_u32(&self) -> bool
Returns true if the field value is of type u32.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u32,
}
let foo = Foo { a: u32::default() };
let field = foo.field("a").unwrap();
assert!(field.is_u32());
assert!(!field.is::<&u32>());Sourcepub fn is_u64(&self) -> bool
pub fn is_u64(&self) -> bool
Returns true if the field value is of type u64.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u64,
}
let foo = Foo { a: u64::default() };
let field = foo.field("a").unwrap();
assert!(field.is_u64());
assert!(!field.is::<&u64>());Sourcepub fn is_u128(&self) -> bool
pub fn is_u128(&self) -> bool
Returns true if the field value is of type u128.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: u128,
}
let foo = Foo { a: u128::default() };
let field = foo.field("a").unwrap();
assert!(field.is_u128());
assert!(!field.is::<&u128>());Sourcepub fn is_usize(&self) -> bool
pub fn is_usize(&self) -> bool
Returns true if the field value is of type usize.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: usize,
}
let foo = Foo { a: usize::default() };
let field = foo.field("a").unwrap();
assert!(field.is_usize());
assert!(!field.is::<&usize>());Sourcepub fn is_i8(&self) -> bool
pub fn is_i8(&self) -> bool
Returns true if the field value is of type i8.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: i8,
}
let foo = Foo { a: i8::default() };
let field = foo.field("a").unwrap();
assert!(field.is_i8());
assert!(!field.is::<&i8>());Sourcepub fn is_i16(&self) -> bool
pub fn is_i16(&self) -> bool
Returns true if the field value is of type i16.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: i16,
}
let foo = Foo { a: i16::default() };
let field = foo.field("a").unwrap();
assert!(field.is_i16());
assert!(!field.is::<&i16>());Sourcepub fn is_i32(&self) -> bool
pub fn is_i32(&self) -> bool
Returns true if the field value is of type i32.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: i32,
}
let foo = Foo { a: i32::default() };
let field = foo.field("a").unwrap();
assert!(field.is_i32());
assert!(!field.is::<&i32>());Sourcepub fn is_i64(&self) -> bool
pub fn is_i64(&self) -> bool
Returns true if the field value is of type i64.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: i64,
}
let foo = Foo { a: i64::default() };
let field = foo.field("a").unwrap();
assert!(field.is_i64());
assert!(!field.is::<&i64>());Sourcepub fn is_i128(&self) -> bool
pub fn is_i128(&self) -> bool
Returns true if the field value is of type i128.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: i128,
}
let foo = Foo { a: i128::default() };
let field = foo.field("a").unwrap();
assert!(field.is_i128());
assert!(!field.is::<&i128>());Sourcepub fn is_isize(&self) -> bool
pub fn is_isize(&self) -> bool
Returns true if the field value is of type isize.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: isize,
}
let foo = Foo { a: isize::default() };
let field = foo.field("a").unwrap();
assert!(field.is_isize());
assert!(!field.is::<&isize>());Sourcepub fn is_f32(&self) -> bool
pub fn is_f32(&self) -> bool
Returns true if the field value is of type f32.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: f32,
}
let foo = Foo { a: f32::default() };
let field = foo.field("a").unwrap();
assert!(field.is_f32());
assert!(!field.is::<&f32>());Sourcepub fn is_f64(&self) -> bool
pub fn is_f64(&self) -> bool
Returns true if the field value is of type f64.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess)]
struct Foo {
a: f64,
}
let foo = Foo { a: f64::default() };
let field = foo.field("a").unwrap();
assert!(field.is_f64());
assert!(!field.is::<&f64>());Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the field value as bool.
This method is guaranteed to return Some(_) if
.is_bool() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into bool.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: bool,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_bool().is_some());Sourcepub fn as_u8(&self) -> Option<u8>
pub fn as_u8(&self) -> Option<u8>
Returns the field value as u8.
This method is guaranteed to return Some(_) if
.is_u8() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into u8.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u8,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_u8().is_some());Sourcepub fn as_u16(&self) -> Option<u16>
pub fn as_u16(&self) -> Option<u16>
Returns the field value as u16.
This method is guaranteed to return Some(_) if
.is_u16() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into u16.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u16,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_u16().is_some());Sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Returns the field value as u32.
This method is guaranteed to return Some(_) if
.is_u32() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into u32.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u32,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_u32().is_some());Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Returns the field value as u64.
This method is guaranteed to return Some(_) if
.is_u64() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into u64.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u64,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_u64().is_some());Sourcepub fn as_u128(&self) -> Option<u128>
pub fn as_u128(&self) -> Option<u128>
Returns the field value as u128.
This method is guaranteed to return Some(_) if
.is_u128() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into u128.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: u128,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_u128().is_some());Sourcepub fn as_usize(&self) -> Option<usize>
pub fn as_usize(&self) -> Option<usize>
Returns the field value as usize.
This method is guaranteed to return Some(_) if
.is_usize() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into usize.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: usize,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_usize().is_some());Sourcepub fn as_i8(&self) -> Option<i8>
pub fn as_i8(&self) -> Option<i8>
Returns the field value as i8.
This method is guaranteed to return Some(_) if
.is_i8() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into i8.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i8,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_i8().is_some());Sourcepub fn as_i16(&self) -> Option<i16>
pub fn as_i16(&self) -> Option<i16>
Returns the field value as i16.
This method is guaranteed to return Some(_) if
.is_i16() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into i16.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i16,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_i16().is_some());Sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
Returns the field value as i32.
This method is guaranteed to return Some(_) if
.is_i32() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into i32.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i32,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_i32().is_some());Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the field value as i64.
This method is guaranteed to return Some(_) if
.is_i64() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into i64.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i64,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_i64().is_some());Sourcepub fn as_i128(&self) -> Option<i128>
pub fn as_i128(&self) -> Option<i128>
Returns the field value as i128.
This method is guaranteed to return Some(_) if
.is_i128() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into i128.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: i128,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_i128().is_some());Sourcepub fn as_isize(&self) -> Option<isize>
pub fn as_isize(&self) -> Option<isize>
Returns the field value as isize.
This method is guaranteed to return Some(_) if
.is_isize() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into isize.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: isize,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_isize().is_some());Sourcepub fn as_f32(&self) -> Option<f32>
pub fn as_f32(&self) -> Option<f32>
Returns the field value as f32.
This method is guaranteed to return Some(_) if
.is_f32() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into f32.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: f32,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_f32().is_some());Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the field value as f64.
This method is guaranteed to return Some(_) if
.is_f64() returns true.
It may also return Some(_) if it is possible to perform a lossless conversion of
the field’s value into f64.
§Example
use field_access::FieldAccess;
#[derive(FieldAccess, Default)]
struct Foo {
a: f64,
}
let mut foo = Foo::default();
let mut field = foo.field("a").unwrap();
assert!(field.as_f64().is_some());