Skip to main content

ScalarValue

Trait ScalarValue 

Source
pub trait ScalarValue: Sized {
    // Required method
    fn from_row(row: &Row, col: usize) -> Option<Self>;
}
Expand description

Trait for types that can be extracted from a scalar query result.

This trait enables the generic Connection::execute_scalar_query method, similar to C++’s executeScalarQuery<T>() template.

§Implementing Custom Types

You can implement this trait for custom types to use them with execute_scalar_query:

impl ScalarValue for MyType {
    fn from_row(row: &Row, col: usize) -> Option<Self> {
        row.get_string(col).map(|s| MyType::parse(&s))
    }
}

Required Methods§

Source

fn from_row(row: &Row, col: usize) -> Option<Self>

Extracts a value of this type from a row at the given column.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ScalarValue for bool

Source§

fn from_row(row: &Row, col: usize) -> Option<Self>

Source§

impl ScalarValue for f64

Source§

fn from_row(row: &Row, col: usize) -> Option<Self>

Source§

impl ScalarValue for i16

Source§

fn from_row(row: &Row, col: usize) -> Option<Self>

Source§

impl ScalarValue for i32

Source§

fn from_row(row: &Row, col: usize) -> Option<Self>

Source§

impl ScalarValue for i64

Source§

fn from_row(row: &Row, col: usize) -> Option<Self>

Source§

impl ScalarValue for String

Source§

fn from_row(row: &Row, col: usize) -> Option<Self>

Implementors§