Debian Codegraph @

src/value.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().;
3
4 use bytesrust-analyzer cargo bytes 1.12.1 crate/::Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#;
5 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::valuerust-analyzer cargo sqlx-core 0.8.3 value/::*;
6
7 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::errorrust-analyzer cargo sqlx-mysql 0.8.3 error/::{BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#, UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#};
8 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::textrust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/::ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#;
9 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::{MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#, MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#};
10
11 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
12 #[repr(u8)]
13 pub enum MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat# {
14 Textrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Text#,
15 Binaryrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#Binary#,
16 }
17
18 /// Implementation of [`Value`] for MySQL.
19 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
20 pub struct MySqlValuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue# {
21 valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#>,
22 type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#type_info.: MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#,
23 formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#format.: MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#,
24 }
25
26 /// Implementation of [`ValueRef`] for MySQL.
27 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
28 pub struct MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r> {
29 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'r [u8]>,
30 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) rowrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#row.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'r Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#>,
31 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#type_info.: MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#,
32 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#format.: MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat#,
33 }
34
35 impl<'r> MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r> {
36 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn formatrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]format().(&self) -> MySqlValueFormatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueFormat# {
37 self.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#format.
38 }
39
40 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn as_bytesrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]as_bytes().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'r [u8], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
41 match &self.valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#value. {
42 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v),
43 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(UnexpectedNullErrorrust-analyzer cargo sqlx-core 0.8.3 error/UnexpectedNullError#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
44 }
45 }
46
47 pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn as_strrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]as_str().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'r str, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
48 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(self.as_bytesrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`]as_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
49 }
50 }
51
52 impl Valuerust-analyzer cargo sqlx-core 0.8.3 value/Value# for MySqlValuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue# {
53 type Databaserust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[MySqlValue][Value]Database# = MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#;
54
55 fn as_refrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[MySqlValue][Value]as_ref().(&self) -> MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'_> {
56 MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef# {
57 valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#value.: self.valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#value..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
58 rowrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#row.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
59 type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#type_info.: self.type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#type_info..clonerust-analyzer cargo sqlx-mysql 0.8.3 type_info/impl#[MySqlTypeInfo][Clone]clone().(),
60 formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#format.: self.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#format.,
61 }
62 }
63
64 fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[MySqlValue][Value]type_info().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#> {
65 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&self.type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#type_info.)
66 }
67
68 fn is_nullrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[MySqlValue][Value]is_null().(&self) -> bool {
69 is_nullrust-analyzer cargo sqlx-mysql 0.8.3 value/is_null().(self.valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#value..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(), &self.type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#type_info.)
70 }
71 }
72
73 impl<'r> ValueRefrust-analyzer cargo sqlx-core 0.8.3 value/ValueRef#<'r> for MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r> {
74 type Databaserust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`][`ValueRef<'r>`]Database# = MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#;
75
76 fn to_ownedrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`][`ValueRef<'r>`]to_owned().(&self) -> MySqlValuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue# {
77 let value = match (self.rowrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#row., self.valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#value.) {
78 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row.slice_refrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]slice_ref().(value)),
79
80 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::copy_from_slicerust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]copy_from_slice().(value)),
81
82 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
83 };
84
85 MySqlValuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue# {
86 valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#value.,
87 formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#format.: self.formatrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#format.,
88 type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValue#type_info.: self.type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#type_info..clonerust-analyzer cargo sqlx-mysql 0.8.3 type_info/impl#[MySqlTypeInfo][Clone]clone().(),
89 }
90 }
91
92 fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`][`ValueRef<'r>`]type_info().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#> {
93 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&self.type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#type_info.)
94 }
95
96 #[inline]
97 fn is_nullrust-analyzer cargo sqlx-mysql 0.8.3 value/impl#[`MySqlValueRef<'r>`][`ValueRef<'r>`]is_null().(&self) -> bool {
98 is_nullrust-analyzer cargo sqlx-mysql 0.8.3 value/is_null().(self.valuerust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#value., &self.type_inforust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#type_info.)
99 }
100 }
101
102 fn is_nullrust-analyzer cargo sqlx-mysql 0.8.3 value/is_null().(value: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]>, ty: &MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#) -> bool {
103 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = value {
104 // zero dates and date times should be treated the same as NULL
105 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
106 ty.r#typerust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#`r#type`.,
107 ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Daterust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Date# | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Timestamprust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Timestamp# | ColumnTyperust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#::Datetimerust-analyzer cargo sqlx-mysql 0.8.3 protocol/text/column/ColumnType#Datetime#
108 ) && value.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(b"\0")
109 {
110 return true;
111 }
112 }
113
114 value.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
115 }