Function SqlState

Source
pub const fn SqlState(value: &'static str) -> SqlState
Expand description

SQLSTATE constant constructor

Can be used to define constant values for SqlState from string literals.

Use SqlState::from_str() for non-literals.

§Panics

Panics if the passed string is not a valid SQLSTATE.

§Examples

const MY_ERROR: SqlState = SqlState("XRUST");

let sqlstate = some_db_query_function(..);

match sqlstate {
  MY_ERROR => println!("got my expected error"),
  _ => panic!("unexpected condition")
}

An invalid SQLSTATE code in a constant context will cause a compile time panic:

const MY_ERROR_CLASS: SqlState = SqlState("!RUST"); // error: evaluation of constant value failed

but an invalid SQLSTATE code in a non-constant context may only panic at runtime:

let some_class = SqlState("!RUST"); // panics