Rust ã® trait 㧠Option<Self> ã Result<Self, E> ã return ããé¢æ°ãå®ç¾©ãããã¨ã㦠[E0277] ã§æãããæã«æãåºãã¡ã¢
åé¡
// âããã¯åé¡ããã¾ãã trait Trait { fn function() -> Self; } // âãã㯠E0277: the size for values of type `Self` cannot be known at compilation time trait TraitOptional { fn function() -> Option<Self>; } // -> Result<Self, E> ã¨ãããå ´åãåæ§ã§ã(çç¥)
åé¿æ¹æ³
// Self ã®ä»£ããã«ã¸ã§ããªã¯ã¹ãåã¾ã㦠trait TraitOptional<T> { fn function() -> Option<T>; } struct Struct{} // impl ããã¨ãã«ã¸ã§ããªã¯ã¹ã®åå¼æ°ã« for ã¨åãåã渡ã impl TraitOptional<Struct> for Struct { fn function() -> Option<Self> { Some( Self{} ) } }