Skip to content

Commit f75e930

Browse files
committed
Allow to specialize FromSql<Text> impl for strings
Again Oracle/liboci is strange…
1 parent 092eba9 commit f75e930

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

diesel/src/type_impls/primitives.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ where
120120
/// impl in terms of `String`, but don't want to allocate. We have to return a
121121
/// raw pointer instead of a reference with a lifetime due to the structure of
122122
/// `FromSql`
123+
#[cfg(not(feature = "unstable"))]
123124
impl<DB> FromSql<sql_types::Text, DB> for *const str
124125
where
125126
DB: Backend + for<'a> BinaryRawValue<'a>,
@@ -132,6 +133,19 @@ where
132133
}
133134
}
134135

136+
#[cfg(feature = "unstable")]
137+
impl<DB> FromSql<sql_types::Text, DB> for *const str
138+
where
139+
DB: Backend + for<'a> BinaryRawValue<'a>,
140+
{
141+
default fn from_sql(value: Option<::backend::RawValue<DB>>) -> deserialize::Result<Self> {
142+
use std::str;
143+
let value = not_none!(value);
144+
let string = str::from_utf8(DB::as_bytes(value))?;
145+
Ok(string as *const _)
146+
}
147+
}
148+
135149
impl<DB: Backend> ToSql<sql_types::Text, DB> for str {
136150
fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> serialize::Result {
137151
out.write_all(self.as_bytes())

0 commit comments

Comments
 (0)