pub struct ConstExpr<'a> { /* private fields */ }Expand description
A borrowed, allocation-free get_const_expr writer over a type’s output text.
The caller supplies output for the exact type and modifier under its session settings.
super::PgValue::output supplies setting-independent output, while its Display uses
DateStyle ISO, TimeZone UTC and IntervalStyle postgres.
use sql_values::postgres::{BuiltinType, ConstExpr, PgValue, ShowType};
let output = PgValue::Integer(-1).output().unwrap().to_string();
let constant = ConstExpr::new(Some(&output), BuiltinType::Integer, ShowType::IfNeeded);
assert_eq!(constant.to_string(), "'-1'::integer");
assert_eq!(ConstExpr::new(None, BuiltinType::Text, ShowType::IfNeeded).to_string(), "NULL::text");Implementations§
Source§impl<'a> ConstExpr<'a>
impl<'a> ConstExpr<'a>
Sourcepub fn new(
output: Option<&'a str>,
target: BuiltinType,
show_type: ShowType,
) -> Self
pub fn new( output: Option<&'a str>, target: BuiltinType, show_type: ShowType, ) -> Self
Wraps type-output text, or None for a typed NULL, with default session quoting.
Sourcepub const fn with_context(self, context: ConstExprContext<'a>) -> Self
pub const fn with_context(self, context: ConstExprContext<'a>) -> Self
Supplies the session quoting and nondefault collation for this constant.
Sourcepub fn needs_type_label(&self) -> bool
pub fn needs_type_label(&self) -> bool
Reports whether this constant’s spelling includes a type label.
use sql_values::postgres::{BuiltinType, ConstExpr, ShowType};
let positive = ConstExpr::new(Some("1"), BuiltinType::Integer, ShowType::IfNeeded);
let negative = ConstExpr::new(Some("-1"), BuiltinType::Integer, ShowType::IfNeeded);
assert!(!positive.needs_type_label());
assert!(negative.needs_type_label());Trait Implementations§
impl<'a> Copy for ConstExpr<'a>
Auto Trait Implementations§
impl<'a> Forget for ConstExpr<'a>
impl<'a> Freeze for ConstExpr<'a>
impl<'a> Move for ConstExpr<'a>
impl<'a> RefUnwindSafe for ConstExpr<'a>
impl<'a> Send for ConstExpr<'a>
impl<'a> Sync for ConstExpr<'a>
impl<'a> Unpin for ConstExpr<'a>
impl<'a> UnsafeUnpin for ConstExpr<'a>where
&'a str: UnsafeUnpin,
impl<'a> UnwindSafe for ConstExpr<'a>where
&'a str: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more