Struct Expr

Source
pub struct Expr<'column, S, T> { /* private fields */ }
Expand description

This is an expression that can be used in queries.

  • The lifetime parameter 'column specifies which columns need to be in scope.
  • The type parameter S specifies the expected schema of the query.
  • And finally the type paramter T specifies the type of the expression.

Expr implements Deref to have table extension methods in case the type is a table type.

Implementations§

Source§

impl<'column, S, T: NumTyp> Expr<'column, S, T>

Source

pub fn add( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>

Add two expressions together.

assert_eq!(txn.query_one(1.into_expr().add(2)), 3);
assert_eq!(txn.query_one(1.0.into_expr().add(2.0)), 3.0);
Source

pub fn sub( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>

Subtract one expression from another.

assert_eq!(txn.query_one(1.into_expr().sub(2)), -1);
assert_eq!(txn.query_one(1.0.into_expr().sub(2.0)), -1.0);
Source

pub fn mul( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>

Multiply two expressions together.

assert_eq!(txn.query_one(2.into_expr().mul(3)), 6);
assert_eq!(txn.query_one(2.0.into_expr().mul(3.0)), 6.0);
Source

pub fn lt( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>

Compute the less than operator (<) of two expressions.

assert_eq!(txn.query_one(2.into_expr().lt(3)), true);
assert_eq!(txn.query_one(1.into_expr().lt(1)), false);
assert_eq!(txn.query_one(3.0.into_expr().lt(1.0)), false);
Source

pub fn lte( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>

Compute the less than or equal operator (<=) of two expressions.

assert_eq!(txn.query_one(2.into_expr().lte(2)), true);
assert_eq!(txn.query_one(3.0.into_expr().lte(1.0)), false);
Source

pub fn gt( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>

Compute the greater than operator (>) of two expressions.

assert_eq!(txn.query_one(2.into_expr().gt(2)), false);
assert_eq!(txn.query_one(3.0.into_expr().gt(1.0)), true);
Source

pub fn gte( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>

Compute the greater than or equal (>=) operator of two expressions.

assert_eq!(txn.query_one(2.into_expr().gte(3)), false);
assert_eq!(txn.query_one(3.0.into_expr().gte(3.0)), true);
Source§

impl<'column, S, T: EqTyp + 'static> Expr<'column, S, T>

Source

pub fn eq( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>

Check whether two expressions are equal.

assert_eq!(txn.query_one(2.into_expr().eq(2)), true);
assert_eq!(txn.query_one(3.0.into_expr().eq(3.0)), true);
assert_eq!(txn.query_one("test".into_expr().eq("test")), true);
assert_eq!(txn.query_one(b"test".into_expr().eq(b"test" as &[u8])), true);
assert_eq!(txn.query_one(false.into_expr().eq(false)), true);

assert_eq!(txn.query_one(1.into_expr().eq(2)), false);
Source§

impl<'column, S> Expr<'column, S, bool>

Source

pub fn not(&self) -> Expr<'column, S, bool>

Checks whether an expression is false.

assert_eq!(txn.query_one(true.into_expr().not()), false);
assert_eq!(txn.query_one(false.into_expr().not()), true);
Source

pub fn and( &self, rhs: impl IntoExpr<'column, S, Typ = bool>, ) -> Expr<'column, S, bool>

Check if two expressions are both true.

assert_eq!(txn.query_one(true.into_expr().and(true)), true);
assert_eq!(txn.query_one(false.into_expr().and(true)), false);
assert_eq!(txn.query_one(false.into_expr().and(false)), false);
Source

pub fn or( &self, rhs: impl IntoExpr<'column, S, Typ = bool>, ) -> Expr<'column, S, bool>

Check if one of two expressions is true.

assert_eq!(txn.query_one(true.into_expr().or(true)), true);
assert_eq!(txn.query_one(false.into_expr().or(true)), true);
assert_eq!(txn.query_one(false.into_expr().or(false)), false);
Source§

impl<'column, S, Typ: 'static> Expr<'column, S, Option<Typ>>

Source

pub fn unwrap_or( &self, rhs: impl IntoExpr<'column, S, Typ = Typ>, ) -> Expr<'column, S, Typ>
where Self: IntoExpr<'column, S, Typ = Option<Typ>>,

Use the first expression if it is Some, otherwise use the second expression.

assert_eq!(txn.query_one(Some(10).into_expr().unwrap_or(5)), 10);
assert_eq!(txn.query_one(None::<String>.into_expr().unwrap_or("foo")), "foo");
Source

pub fn is_some(&self) -> Expr<'column, S, bool>

Check that the expression is Some.

assert_eq!(txn.query_one(Some(10).into_expr().is_some()), true);
assert_eq!(txn.query_one(None::<i64>.into_expr().is_some()), false);
Source

pub fn is_none(&self) -> Expr<'column, S, bool>

Check that the expression is None.

assert_eq!(txn.query_one(Some(10).into_expr().is_none()), false);
assert_eq!(txn.query_one(None::<i64>.into_expr().is_none()), true);
Source§

impl<'column, S> Expr<'column, S, i64>

Source

pub fn as_float(&self) -> Expr<'column, S, f64>

Convert the i64 expression to f64 type.

assert_eq!(txn.query_one(10.into_expr().as_float()), 10.0);
Source§

impl<'column, S> Expr<'column, S, String>

Source

pub fn starts_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>

Check if the expression starts with the string pattern.

Matches case-sensitive. The pattern gets automatically escaped.

assert_eq!(txn.query_one("hello world".into_expr().starts_with("hello")), true);
assert_eq!(txn.query_one("hello world".into_expr().starts_with("Hello")), false);
Source

pub fn ends_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>

Check if the expression ends with the string pattern.

Matches case-sensitive. The pattern gets automatically escaped.

assert_eq!(txn.query_one("hello world".into_expr().ends_with("world")), true);
assert_eq!(txn.query_one("hello world".into_expr().ends_with("World")), false);
Source

pub fn contains(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>

Check if the expression contains the string pattern.

Matches case-sensitive. The pattern gets automatically escaped.

assert_eq!(txn.query_one("rhubarb".into_expr().contains("bar")), true);
assert_eq!(txn.query_one("rhubarb".into_expr().contains("Bar")), false);
Source

pub fn glob( &self, rhs: impl IntoExpr<'column, S, Typ = String>, ) -> Expr<'column, S, bool>

Check if the expression matches the pattern docs.

This is a case-sensitive version of like. It uses Unix file globbing syntax for wild cards. * matches any sequence of characters and ? matches any single character. [0-9] matches any single digit and [a-z] matches any single lowercase letter. ^ negates the pattern.

assert_eq!(txn.query_one("hello world".into_expr().glob("?ello*")), true);
assert_eq!(txn.query_one("hello world".into_expr().glob("Hell*")), false);
Source

pub fn like(&self, pattern: impl Into<String>) -> Expr<'column, S, bool>

Check if the expression matches the pattern docs.

As noted in the docs, it is case-insensitive for ASCII characters. Other characters are case-sensitive. For creating patterns it uses % as a wildcard for any sequence of characters and _ for any single character. Special characters should be escaped with \.

assert_eq!(txn.query_one("hello world".into_expr().like("HELLO%")), true);
assert_eq!(txn.query_one("hello world".into_expr().like("he_o%")), false);

Trait Implementations§

Source§

impl<S, T> Clone for Expr<'_, S, T>

Source§

fn clone(&self) -> Self

Returns a copy 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<S, T> Debug for Expr<'_, S, T>

Source§

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

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

impl<S, T: Table> Deref for Expr<'_, S, T>

Source§

type Target = <T as Table>::Ext<Expr<'_, S, T>>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'column, S, T: MyTyp> IntoExpr<'column, S> for Expr<'column, S, T>

Source§

type Typ = T

The type of the expression.
Source§

fn into_expr(self) -> Expr<'column, S, Self::Typ>

Turn this value into an Expr.
Source§

impl<'columns, 'transaction, S, T> IntoSelect<'columns, 'transaction, S> for Expr<'columns, S, T>
where T: MyTyp,

Source§

type Out = <T as MyTyp>::Out<'transaction>

The type that results from executing the Select.
Source§

fn into_select(self) -> Select<'columns, 'transaction, S, Self::Out>

This method is what tells rust-query how to turn the value into a Select. Read more

Auto Trait Implementations§

§

impl<'column, S, T> Freeze for Expr<'column, S, T>

§

impl<'column, S, T> !RefUnwindSafe for Expr<'column, S, T>

§

impl<'column, S, T> !Send for Expr<'column, S, T>

§

impl<'column, S, T> !Sync for Expr<'column, S, T>

§

impl<'column, S, T> Unpin for Expr<'column, S, T>
where S: Unpin,

§

impl<'column, S, T> !UnwindSafe for Expr<'column, S, T>

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<'columns, 'transaction, S, X> IntoSelectExt<'columns, 'transaction, S> for X
where X: IntoSelect<'columns, 'transaction, S>,

Source§

fn map_select<T>( self, f: impl FnMut(<X as IntoSelect<'columns, 'transaction, S>>::Out) -> T + 'transaction, ) -> Select<'columns, 'transaction, S, T>

👎Deprecated: Please use Select::map
Refer to Select::map.
Source§

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

Source§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
Source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
Source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
Source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
Source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
Source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
Source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
Source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
Source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
Source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
Source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
Source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
Source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
Source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
Source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
Source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
Source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
Source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
Source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
Source§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
Source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
Source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
Source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
Source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
Source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
Source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
Source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
Source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
Source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
Source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
Source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
Source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
Source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
Source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
Source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
Source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
Source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
Source§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling Attribute value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
Source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
Source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
Source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
Source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
Source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
Source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
Source§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi Quirk value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
Source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
Source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
Source§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
Source§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
Source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
Source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
Source§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the Condition value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
Source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V