Skip to main content

FieldRef

Struct FieldRef 

Source
pub struct FieldRef<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> FieldRef<'a>

Source

pub fn name(&self) -> String

Examples found in repository?
examples/query_records.rs (line 26)
5fn main() {
6    let mut args = std::env::args().skip(1);
7    let path = args
8        .next()
9        .expect("usage: query_records <file.rec> <Type> <selection-expression>");
10    let rset_type = args.next().expect("missing record type");
11    let expr = args.next().expect("missing selection expression");
12
13    let text = fs::read_to_string(&path).expect("read file");
14    let mut db = Db::parse_str(&text).expect("parse");
15
16    let rset = db
17        .rset_by_type(&rset_type)
18        .unwrap_or_else(|| panic!("no record set of type {rset_type:?}"));
19    let selection_expression =
20        SelectionExpression::compile(&expr, false).expect("compile selection expression");
21
22    let mut matches = 0usize;
23    for record in rset.records().filter(|r| selection_expression.matches(r)) {
24        matches += 1;
25        for field in record.fields() {
26            println!("{}: {}", field.name(), field.value());
27        }
28        println!();
29    }
30    eprintln!("{matches} match(es)");
31}
Source

pub fn value(&self) -> String

Examples found in repository?
examples/query_records.rs (line 26)
5fn main() {
6    let mut args = std::env::args().skip(1);
7    let path = args
8        .next()
9        .expect("usage: query_records <file.rec> <Type> <selection-expression>");
10    let rset_type = args.next().expect("missing record type");
11    let expr = args.next().expect("missing selection expression");
12
13    let text = fs::read_to_string(&path).expect("read file");
14    let mut db = Db::parse_str(&text).expect("parse");
15
16    let rset = db
17        .rset_by_type(&rset_type)
18        .unwrap_or_else(|| panic!("no record set of type {rset_type:?}"));
19    let selection_expression =
20        SelectionExpression::compile(&expr, false).expect("compile selection expression");
21
22    let mut matches = 0usize;
23    for record in rset.records().filter(|r| selection_expression.matches(r)) {
24        matches += 1;
25        for field in record.fields() {
26            println!("{}: {}", field.name(), field.value());
27        }
28        println!();
29    }
30    eprintln!("{matches} match(es)");
31}

Auto Trait Implementations§

§

impl<'a> Freeze for FieldRef<'a>

§

impl<'a> RefUnwindSafe for FieldRef<'a>

§

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

§

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

§

impl<'a> Unpin for FieldRef<'a>

§

impl<'a> UnsafeUnpin for FieldRef<'a>

§

impl<'a> UnwindSafe for FieldRef<'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<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.