mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Merge pull request #215 from reddraggone9/doc_comment_fix
Fix doc comment example of FromSql/ToSql
This commit is contained in:
commit
29e276ef9d
@ -17,19 +17,17 @@
|
|||||||
//! truncates timespecs to the nearest second. If you want different storage for timespecs, you can
|
//! truncates timespecs to the nearest second. If you want different storage for timespecs, you can
|
||||||
//! use a newtype. For example, to store timespecs as `f64`s:
|
//! use a newtype. For example, to store timespecs as `f64`s:
|
||||||
//!
|
//!
|
||||||
//! ```rust,ignore
|
//! ```rust
|
||||||
//! extern crate rusqlite;
|
//! extern crate rusqlite;
|
||||||
//! extern crate libc;
|
//! extern crate time;
|
||||||
//!
|
//!
|
||||||
//! use rusqlite::types::{FromSql, ToSql, sqlite3_stmt};
|
//! use rusqlite::types::{FromSql, FromSqlResult, ValueRef, ToSql, ToSqlOutput};
|
||||||
//! use rusqlite::{Result};
|
//! use rusqlite::{Result};
|
||||||
//! use libc::c_int;
|
|
||||||
//! use time;
|
|
||||||
//!
|
//!
|
||||||
//! pub struct TimespecSql(pub time::Timespec);
|
//! pub struct TimespecSql(pub time::Timespec);
|
||||||
//!
|
//!
|
||||||
//! impl FromSql for TimespecSql {
|
//! impl FromSql for TimespecSql {
|
||||||
//! fn column_result(value: ValueRef) -> Result<Self> {
|
//! fn column_result(value: ValueRef) -> FromSqlResult<Self> {
|
||||||
//! f64::column_result(value).map(|as_f64| {
|
//! f64::column_result(value).map(|as_f64| {
|
||||||
//! TimespecSql(time::Timespec{ sec: as_f64.trunc() as i64,
|
//! TimespecSql(time::Timespec{ sec: as_f64.trunc() as i64,
|
||||||
//! nsec: (as_f64.fract() * 1.0e9) as i32 })
|
//! nsec: (as_f64.fract() * 1.0e9) as i32 })
|
||||||
@ -38,12 +36,15 @@
|
|||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! impl ToSql for TimespecSql {
|
//! impl ToSql for TimespecSql {
|
||||||
//! unsafe fn bind_parameter(&self, stmt: *mut sqlite3_stmt, col: c_int) -> c_int {
|
//! fn to_sql(&self) -> Result<ToSqlOutput> {
|
||||||
//! let TimespecSql(ts) = *self;
|
//! let TimespecSql(ts) = *self;
|
||||||
//! let as_f64 = ts.sec as f64 + (ts.nsec as f64) / 1.0e9;
|
//! let as_f64 = ts.sec as f64 + (ts.nsec as f64) / 1.0e9;
|
||||||
//! as_f64.bind_parameter(stmt, col)
|
//! Ok(as_f64.into())
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
|
//!
|
||||||
|
//! # // Prevent this doc test from being wrapped in a `fn main()` so that it will compile.
|
||||||
|
//! # fn main() {}
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! `ToSql` and `FromSql` are also implemented for `Option<T>` where `T` implements `ToSql` or
|
//! `ToSql` and `FromSql` are also implemented for `Option<T>` where `T` implements `ToSql` or
|
||||||
|
Loading…
Reference in New Issue
Block a user