Debian Codegraph @

src/types/text.rs

raw symbols SCIP
1 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#, MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#};
2 use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::decoderust-analyzer cargo sqlx-core 0.8.3 decode/::Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#;
3 use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::encoderust-analyzer cargo sqlx-core 0.8.3 encode/::{Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#, IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#};
4 use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#;
5 use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::typesrust-analyzer cargo sqlx-core 0.8.3 types/::{Textrust-analyzer cargo sqlx-core 0.8.3 types/text/Text#, Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#};
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#;
7 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/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
8
9 impl<T> Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Textrust-analyzer cargo sqlx-core 0.8.3 types/text/Text#<T> {
10 fn type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/text/impl#[`Text<T>`][`Type<MySql>`]type_info().() -> MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo# {
11 <Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# as Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#>>::type_inforust-analyzer cargo sqlx-mysql 0.8.3 types/str/impl#[String][`Type<MySql>`]type_info().()
12 }
13
14 fn compatiblerust-analyzer cargo sqlx-mysql 0.8.3 types/text/impl#[`Text<T>`][`Type<MySql>`]compatible().(ty: &MySqlTypeInforust-analyzer cargo sqlx-mysql 0.8.3 type_info/MySqlTypeInfo#) -> bool {
15 <Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# as Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#>>::compatiblerust-analyzer cargo sqlx-mysql 0.8.3 types/str/impl#[String][`Type<MySql>`]compatible().(ty)
16 }
17 }
18
19 impl<'q, T> Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'q, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Textrust-analyzer cargo sqlx-core 0.8.3 types/text/Text#<T>
20 where
21 T: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#,
22 {
23 fn encode_by_refrust-analyzer cargo sqlx-mysql 0.8.3 types/text/impl#[`Text<T>`][`Encode<'q, MySql>`]encode_by_ref().(&self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
24 // We can't really do the trick like with Postgres where we reserve the space for the
25 // length up-front and then overwrite it later, because MySQL appears to enforce that
26 // length-encoded integers use the smallest encoding for the value:
27 // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_dt_integers.html#sect_protocol_basic_dt_int_le
28 //
29 // So we'd have to reserve space for the max-width encoding, format into the buffer,
30 // then figure out how many bytes our length-encoded integer needs to be and move the
31 // value bytes down to use up the empty space.
32 //
33 // Copying from a completely separate buffer instead is easier. It may or may not be faster
34 // or slower depending on a ton of different variables, but I don't currently have the time
35 // to implement both approaches and compare their performance.
36 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#encode().(self.0rust-analyzer cargo sqlx-core 0.8.3 types/text/Text#0..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), buf)
37 }
38 }
39
40 impl<'r, T> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#> for Textrust-analyzer cargo sqlx-core 0.8.3 types/text/Text#<T>
41 where
42 T: FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#,
43 BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#: Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<<T as FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#>::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#>,
44 {
45 fn decoderust-analyzer cargo sqlx-mysql 0.8.3 types/text/impl#[`Text<T>`][`Decode<'r, MySql>`]decode().(value: MySqlValueRefrust-analyzer cargo sqlx-mysql 0.8.3 value/MySqlValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/text/impl#[`Text<T>`][`Decode<'r, MySql>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
46 let s: &str = Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#::<MySqlrust-analyzer cargo sqlx-mysql 0.8.3 database/MySql#>::decoderust-analyzer cargo sqlx-mysql 0.8.3 types/str/impl#[`&'r str`][`Decode<'r, MySql>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
47 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-mysql 0.8.3 types/text/impl#[`Text<T>`][`Decode<'r, MySql>`](s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().))
48 }
49 }