This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! newtype patternで簡単に元の型と同等の機能を提供するには? | |
use itertools::Itertools; | |
macro_rules! impl_as { | |
($newtype:ty, $basetype:ty, $field:tt, $method:ident) => { | |
impl $newtype { | |
fn $method(&self) -> &$basetype { | |
&self.$field | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! この方法の方でCakeパターンをするとintellij-rustでの補完が効くケースが多い。 | |
type Error = Box<std::error::Error>; | |
#[derive(Debug, Clone, Copy)] | |
struct EmployeeId(u64); | |
#[derive(Debug)] | |
struct Employee { | |
id: EmployeeId, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub mod person { | |
use std::marker::PhantomData; | |
#[derive(Debug)] | |
pub struct Person { | |
name: String, | |
age: u8, | |
} | |
impl Person { |