|
@@ -3,7 +3,7 @@ use std::cell::RefCell;
|
|
use std::fmt::Write as FmtWrite;
|
|
use std::fmt::Write as FmtWrite;
|
|
use std::io;
|
|
use std::io;
|
|
|
|
|
|
-use bytes::Bytes;
|
|
|
|
|
|
+use bytes::{Bytes, BytesMut};
|
|
use futures::stream::futures_unordered::FuturesUnordered;
|
|
use futures::stream::futures_unordered::FuturesUnordered;
|
|
use futures::{Future, FutureExt, StreamExt, TryStreamExt};
|
|
use futures::{Future, FutureExt, StreamExt, TryStreamExt};
|
|
use ntex::web::Error;
|
|
use ntex::web::Error;
|
|
@@ -11,7 +11,7 @@ use random_fast_rng::{FastRng, Random};
|
|
use smallvec::SmallVec;
|
|
use smallvec::SmallVec;
|
|
use tokio_postgres::types::ToSql;
|
|
use tokio_postgres::types::ToSql;
|
|
use tokio_postgres::{connect, Client, NoTls, Statement};
|
|
use tokio_postgres::{connect, Client, NoTls, Statement};
|
|
-use yarte::{Serialize, TemplateBytes};
|
|
|
|
|
|
+use yarte::{ywrite_html, Serialize};
|
|
|
|
|
|
#[derive(Serialize, Debug)]
|
|
#[derive(Serialize, Debug)]
|
|
pub struct World {
|
|
pub struct World {
|
|
@@ -25,12 +25,6 @@ pub struct Fortune {
|
|
pub message: Cow<'static, str>,
|
|
pub message: Cow<'static, str>,
|
|
}
|
|
}
|
|
|
|
|
|
-#[derive(TemplateBytes)]
|
|
|
|
-#[template(path = "fortune")]
|
|
|
|
-pub struct FortunesTemplate {
|
|
|
|
- pub fortunes: SmallVec<[Fortune; 32]>,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/// Postgres interface
|
|
/// Postgres interface
|
|
pub struct PgConnection {
|
|
pub struct PgConnection {
|
|
cl: Client,
|
|
cl: Client,
|
|
@@ -92,7 +86,7 @@ impl PgConnection {
|
|
id: row.get(0),
|
|
id: row.get(0),
|
|
randomnumber: row.get(1),
|
|
randomnumber: row.get(1),
|
|
}
|
|
}
|
|
- .to_bytes(40))
|
|
|
|
|
|
+ .to_bytes::<BytesMut>(40))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -194,7 +188,10 @@ impl PgConnection {
|
|
|
|
|
|
fortunes.sort_by(|it, next| it.message.cmp(&next.message));
|
|
fortunes.sort_by(|it, next| it.message.cmp(&next.message));
|
|
|
|
|
|
- Ok(FortunesTemplate { fortunes }.ccall(2048))
|
|
|
|
|
|
+ let mut buf = BytesMut::with_capacity(2048);
|
|
|
|
+ ywrite_html!(buf, "{{> fortune }}");
|
|
|
|
+
|
|
|
|
+ Ok(buf.freeze())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|