제네릭 공부중

This commit is contained in:
blacktoast 2021-10-15 07:46:27 +00:00
parent 8de108505d
commit df475c65c0
4 changed files with 8 additions and 11 deletions

View File

@ -3,15 +3,14 @@
// This program uses a completed version of the code from errors4. // This program uses a completed version of the code from errors4.
// It won't compile right now! Why? // It won't compile right now! Why?
// Execute `rustlings hint errors5` for hints! // Execute `rustlings hint errors5` for hints!
//못품 일단 넘기기
// I AM NOT DONE
use std::error; use std::error;
use std::fmt; use std::fmt;
use std::num::ParseIntError; use std::num::ParseIntError;
// TODO: update the return type of `main()` to make this compile. // TODO: update the return type of `main()` to make this compile.
fn main() -> Result<(), (ParseIntError,CreationError)> { fn main() -> Result<(),ParseIntError> {
let pretend_user_input = "42"; let pretend_user_input = "42";
let x: i64 = pretend_user_input.parse()?; let x: i64 = pretend_user_input.parse()?;
println!("output={:?}", PositiveNonzeroInteger::new(x)?); println!("output={:?}", PositiveNonzeroInteger::new(x)?);

View File

@ -8,7 +8,7 @@
// Make these tests pass! Execute `rustlings hint errors6` for hints :) // Make these tests pass! Execute `rustlings hint errors6` for hints :)
// I AM NOT DONE // 일단 넘김 패스
use std::num::ParseIntError; use std::num::ParseIntError;

View File

@ -3,9 +3,8 @@
// Execute `rustlings hint generics1` for hints! // Execute `rustlings hint generics1` for hints!
// I AM NOT DONE
fn main() { fn main() {
let mut shopping_list: Vec<?> = Vec::new(); let mut shopping_list: Vec<&str> = Vec::new();
shopping_list.push("milk"); shopping_list.push("milk");
} }

View File

@ -3,14 +3,13 @@
// Execute `rustlings hint generics2` for hints! // Execute `rustlings hint generics2` for hints!
// I AM NOT DONE
struct Wrapper { struct Wrapper<T> {
value: u32, value: T,
} }
impl Wrapper { impl<T> Wrapper<T> {
pub fn new(value: u32) -> Self { pub fn new (value: T) -> Self {
Wrapper { value } Wrapper { value }
} }
} }