diesel/sqlite/connection/
collation_needed.rs1#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
4extern crate libsqlite3_sys as ffi;
5
6#[cfg(all(target_family = "wasm", target_os = "unknown"))]
7use sqlite_wasm_rs as ffi;
8
9#[derive(#[automatically_derived]
impl ::core::fmt::Debug for SqliteTextRep {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
SqliteTextRep::Utf8 =>
::core::fmt::Formatter::write_str(f, "Utf8"),
SqliteTextRep::Utf16Be =>
::core::fmt::Formatter::write_str(f, "Utf16Be"),
SqliteTextRep::Utf16Le =>
::core::fmt::Formatter::write_str(f, "Utf16Le"),
SqliteTextRep::Other(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Other",
&__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for SqliteTextRep {
#[inline]
fn clone(&self) -> SqliteTextRep {
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for SqliteTextRep { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for SqliteTextRep {
#[inline]
fn eq(&self, other: &SqliteTextRep) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(SqliteTextRep::Other(__self_0),
SqliteTextRep::Other(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for SqliteTextRep {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<i32>;
}
}Eq)]
14#[non_exhaustive]
15pub enum SqliteTextRep {
16 Utf8,
18 Utf16Be,
20 Utf16Le,
22 Other(i32),
26}
27
28impl SqliteTextRep {
29 pub(super) fn from_ffi(text_rep: i32) -> Self {
30 match text_rep {
31 ffi::SQLITE_UTF8 => SqliteTextRep::Utf8,
32 ffi::SQLITE_UTF16BE => SqliteTextRep::Utf16Be,
33 ffi::SQLITE_UTF16LE => SqliteTextRep::Utf16Le,
34 other => SqliteTextRep::Other(other),
35 }
36 }
37}
38
39#[derive(#[automatically_derived]
impl<'a> ::core::fmt::Debug for CollationNeededContext<'a> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"CollationNeededContext", "name", &self.name, "text_rep",
&&self.text_rep)
}
}Debug, #[automatically_derived]
impl<'a> ::core::clone::Clone for CollationNeededContext<'a> {
#[inline]
fn clone(&self) -> CollationNeededContext<'a> {
let _: ::core::clone::AssertParamIsClone<&'a str>;
let _: ::core::clone::AssertParamIsClone<SqliteTextRep>;
*self
}
}Clone, #[automatically_derived]
impl<'a> ::core::marker::Copy for CollationNeededContext<'a> { }Copy)]
43#[non_exhaustive]
44pub struct CollationNeededContext<'a> {
45 pub name: &'a str,
47 pub text_rep: SqliteTextRep,
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[diesel_test_helper::test]
56 fn from_ffi_maps_all_documented_variants() {
57 assert_eq!(
58 SqliteTextRep::from_ffi(ffi::SQLITE_UTF8),
59 SqliteTextRep::Utf8
60 );
61 assert_eq!(
62 SqliteTextRep::from_ffi(ffi::SQLITE_UTF16BE),
63 SqliteTextRep::Utf16Be,
64 );
65 assert_eq!(
66 SqliteTextRep::from_ffi(ffi::SQLITE_UTF16LE),
67 SqliteTextRep::Utf16Le,
68 );
69 }
70
71 #[diesel_test_helper::test]
72 fn from_ffi_preserves_unknown_encodings_in_other() {
73 assert_eq!(SqliteTextRep::from_ffi(999), SqliteTextRep::Other(999));
76 }
77}