Struct FieldName

Source
pub struct FieldName(/* private fields */);
Expand description

A single dotted path (e.g. "database.url" or "a").

Created for you by Foo::fields().some_field().

Implementations§

Source§

impl FieldName

Source

pub fn as_str(&self) -> &str

Get the dotted string path (borrowed).

Source

pub fn static_lit(lit: &'static str) -> Self

Build a Field from a &'static str literal with zero allocation.

Source

pub fn from_string(s: String) -> Self

Build a Field from an owned String (one allocation already paid).

Examples found in repository?
examples/fields.rs (line 27)
27    Move(i32, i32),         // "Move.item0", "Move.item1"
28    Write
Source

pub fn join(prefix: &str, key: &'static str) -> Self

Append key to the (possibly empty) prefix.

Examples found in repository?
examples/fields.rs (line 7)
7    a: i64,
8    bar: Bar,
9}
10
11#[derive(Fields, Serialize, Deserialize, Debug, Clone)]
12struct Bar {
13    c: String,
14    b: Baz,
15    z: Baz,
16}
17#[derive(Fields, Serialize, Deserialize, Debug, Clone)]
18struct Baz {
19    d: String,
20}
21#[derive(Fields)]
22pub struct Vec2(pub f32, pub f32);
23
24#[derive(Fields)]
25pub enum Message {
26    Quit,                   // "Quit"
27    Move(i32, i32),         // "Move.item0", "Move.item1"
28    Write { text
More examples
Hide additional examples
examples/watch.rs (line 7)
7    a: i64,
8    bar: Bar,
9}
10
11#[derive(Fields, Serialize, Deserialize, Debug, Clone)]
12struct Bar {
13    c: String,
14    b: Baz,
15}
16#[derive(Fields, Serialize, Deserialize, Debug, Clone)]
17struct Baz {
18    d
examples/complex.rs (line 15)
15    street: String,
16    city: String,
17}
18
19#[derive(Diff, Fields, Clone, Debug, Serialize, Deserialize)]
20pub struct Account {
21    id: u32,
22    username: String,
23    password: String,
24    roles: HashSet<String>,
25    preferences: HashMap<String, String>,
26    address: Address,
27}
28
29impl PartialEq for Account {
30    fn eq(&self, other: &Self) -> bool {
31        self.id == other.id
32    }
33}
34impl Eq for Account {}
35impl Hash for Account {
36    fn hash<H: Hasher>(&self, s: &mut H) {
37        self.id.hash(s)
38    }
39}
40
41#[derive(Diff, Fields, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
42pub struct Company {
43    name: String,
44    staff

Trait Implementations§

Source§

impl AsField for FieldName

Source§

impl Clone for FieldName

Source§

fn clone(&self) -> FieldName

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldName

Source§

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

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

impl Hash for FieldName

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FieldName

Source§

fn eq(&self, other: &FieldName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for FieldName

Source§

impl StructuralPartialEq for FieldName

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.