takeable-option-0.5.0/Cargo.toml.orig010064400017500001750000000003041351273663300157100ustar0000000000000000[package] name = "takeable-option" version = "0.5.0" authors = ["Hal Gentz "] license = "Apache-2.0 OR MIT" description = "A small wrapper around option." [dependencies] takeable-option-0.5.0/Cargo.toml0000644000000013210000000000000121460ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "takeable-option" version = "0.5.0" authors = ["Hal Gentz "] description = "A small wrapper around option." license = "Apache-2.0 OR MIT" [dependencies] takeable-option-0.5.0/src/lib.rs010064400017500001750000000025661351273707300147370ustar0000000000000000use std::ops::{Deref, DerefMut}; #[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd, Eq, Ord, Hash)] pub struct Takeable(Option); impl Takeable { #[inline] pub fn new(value: T) -> Takeable { Takeable(Some(value)) } #[inline] pub fn new_empty() -> Takeable { Takeable(None) } #[inline] pub fn take(takeable: &mut Takeable) -> T { takeable.0.take().unwrap() } #[inline] pub fn try_take(takeable: &mut Takeable) -> Option { takeable.0.take() } #[inline] pub fn new_take(takeable: &mut Takeable) -> Takeable { Takeable::new(takeable.0.take().unwrap()) } #[inline] pub fn insert(takeable: &mut Takeable, new_takeable: T) -> Option { let ret = takeable.0.take(); takeable.0 = Some(new_takeable); ret } #[inline] pub fn to_opt(takeable: Takeable) -> Option { takeable.0 } } impl From> for Takeable { #[inline] fn from(op: Option) -> Self { Takeable(op) } } impl Deref for Takeable { type Target = T; #[inline] fn deref(&self) -> &Self::Target { self.0.as_ref().unwrap() } } impl DerefMut for Takeable { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { self.0.as_mut().unwrap() } }