FieldMut

Struct FieldMut 

Source
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>

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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]);
Source

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"));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>>§

Source

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>());
Source

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>());
Source

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);
Source

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));
Source

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>());
Source

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][..]));
Source

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>());
Source

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());
Source

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());
Source

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"));
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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>());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());

Trait Implementations§

Source§

impl<'a> AsRef<Field<'a>> for FieldMut<'a>

Source§

fn as_ref(&self) -> &Field<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Debug for FieldMut<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Deref for FieldMut<'a>

Source§

type Target = Field<'a>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'a> Freeze for FieldMut<'a>

§

impl<'a> !RefUnwindSafe for FieldMut<'a>

§

impl<'a> !Send for FieldMut<'a>

§

impl<'a> !Sync for FieldMut<'a>

§

impl<'a> Unpin for FieldMut<'a>

§

impl<'a> !UnwindSafe for FieldMut<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.