Skip to content

Instantly share code, notes, and snippets.

View rrichardson's full-sized avatar
💭
⚔️ Hacking Away

Rick Richardson rrichardson

💭
⚔️ Hacking Away
View GitHub Profile
impl Serialize for PlatformNotification {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
use self::PlatformNotification::*;
match self {
&Apn(ref apn, _) => apn.serialize(serializer),
&Gcm(ref gcm, _) => gcm.serialize(serializer),
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[serde(untagged)]
pub enum PlatformNotification {
Apn(
ApnNotification,
#[serde(skip)]
Url),
Gcm(
GcmNotification,
#[serde(skip)]
rustup_date() {
if [ -z "$1" ]; then
echo "usage: rustup_date 'YYYY-MM-DD'"
else
rustup override set nightly-${1}
rustup default nightly-${1}
rustup component add rls-preview --toolchain nightly-${1}
rustup component add rust-analysis --toolchain nightly-${1}
rustup component add rust-src --toolchain nightly-${1}
fi
impl<K,T> Set<K,T>
where K : Serialize + DeserializeOwned + Ord + Clone,
T : Serialize + DeserializeOwned + Ord + Clone,
{
pub fn new(db: Arc<DB>, cf: ColumnFamily) -> Set<K,T> {
Set { db, cf, p1: PhantomData, p2: PhantomData }
}
pub fn create<I>(&self, key: &K, values: I, ttl: Option<i64>) -> Result<(), Error>
where for<'a> &'a I: IntoIterator<Item=&'a T> {
impl<K,U,V> Map<K,U,V>
where K: Serialize + DeserializeOwned + Ord + Clone,
U: Serialize + DeserializeOwned + Ord + Clone,
V: Serialize + DeserializeOwned + Clone,
{
pub fn new(db: Arc<DB>, cf: ColumnFamily) -> Map<K,U,V> {
Map { db, cf, p1: PhantomData, p2: PhantomData, p3: PhantomData }
}
pub fn create<'a, I>(&self, key: &K, values: I, ttl: Option<i64>) -> Result<(), Error>
@rrichardson
rrichardson / l.rs
Created October 27, 2017 19:41
lifetimes
pub fn create<'a, I>(&self, key: &K, values: I, ttl: Option<i64>) -> Result<(), Error>
where I: Iterator<Item=&'a T>
{
let kbuf = serialize(&key, Infinite)?;
let mut vbuf : Vec<u8> = Vec::with_capacity(32);
set_ttl(&mut vbuf, ttl)?;
{
let val : VecDeque<&T> = values.collect();
serialize_into(&mut vbuf, &val, Infinite).map_err(Error::from)?;
}
pub fn get<'de, V>(&self, key: &[u8]) -> Result<Option<V>, Error>
where
V: Deserialize<'de>,
{
let res = self.db.get_cf(self.cf, key)?;
if let Some(inbuf) = res {
let v: V = deserialize(&inbuf[HDR_LEN..]).map_err(Error::from)?;
Ok(Some(v))
} else {
Ok(None)
thread '<unnamed>' panicked at 'could not run cargo: CargoError(Msg("failed to run `rustc` to learn about target-specific information"), State { next_error: Some(CargoError(ProcessErrorKind(ProcessError { desc: "process didn\'t exit successfully: `rustc - --crate-name ___ --print=file-names --error-format=json -Zcontinue-parse-after-error -Zsave-analysis -Zunstable-options --target x86_64-unknown-linux-gnu --crate-type bin --crate-type rlib` (exit code: 101)\n--- stderr\nerror: the option `Z` is only accepted on the nightly compiler\n\n", exit: Some(ExitStatus(ExitStatus(25856))), output: Some(Output { status: ExitStatus(ExitStatus(25856)), stdout: "", stderr: "error: the option `Z` is only accepted on the nightly compiler\n\n" }) }), State { next_error: None, backtrace: None })), backtrace: None })', /checkout/src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error[E0308]: mismatched types
--> /home/rick/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.7.0/src/path/parser.rs:68:32
|
68 | return result.to_result();
| ^^^^^^^^^^^^^^^^^^ expected enum `nom::ErrorKind`, found enum `nom::Err`
|
= note: expected type `std::result::Result<_, nom::ErrorKind>`
found type `std::result::Result<_, nom::Err<&[u8]>>`
error[E0308]: match arms have incompatible types
@rrichardson
rrichardson / install_rls.sh
Last active October 20, 2017 14:06
installing rust language server and vim8 plugins
#!/bin/bash -e
# Rick Richardson <rick.richardson@gmail.com>
# License Apache2 or MIT
# * What this does *
#
# This script will install RLS and the Vim Language Server Plugin found here :
# https://github.com/prabirshrestha/vim-lsp
# * Credit *