Rust 몰라요.
Rust 어려움
알 수 없는 일을 쓰다.부정기적으로 업데이트하다.이것은 나의 쪽지이니 탓하지 마세요.
iter () 및 intoiter ()의 차이점
읽기https://dawn.hateblo.jp/entry/2017/07/24/165933는 게 좋아요.
iter()
move를 하지 않습니다.참조된 모음을 Iterator로 만듭니다.into_iter()
move를 진행합니다.값의 모음집을 iterator로 만듭니다.Box 정보<dyn Error>
읽기https://text.baldanders.info/rust-lang/error-handling/는 게 좋아요.
범용 오류에 사용합니다.
아래와 같다
fn parse_from_stdin() -> Result<u32, std::num::ParseIntError> {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf)?; //Compile error: `?` couldn't convert the error to `std::num::ParseIntError`
buf.trim().parse::<u32>()
}
는 다음과 같다.fn parse_from_stdin() -> Result<u32, Box<dyn std::error::Error>> {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf)?;
let n = buf.trim().parse::<u32>()?;
Ok(n)
}
fn main() {
println!("{:?}", parse_from_stdin());
}
왜.Rust Compuiler는 함수의 반환 값에 필요한 크기를 알기 위해 특정 유형을 반환 값의 유형으로 표시해야 합니다.예를 들어 Trait
를 반환 값의 유형으로 설정할 수 없습니다.이렇게 하면 어려움도 있으니
Box
로 되돌아오면 된다.box
heap에 있는 메모리의 참조를 나타낸다.참조는 statically-known
사이즈이기 때문에 커뮤니케이터는 용서할 수 있습니다.이거 권투 아니에요?그래서Rust는 가능한 한 명확하게 heap에 메모리를 확보하려고 하기 때문에 이런 일을 하려면
Box
키워드를 붙여야 한다.dyn 정보
읽기https://laysakura.github.io/2020/05/21/rust-static-lifetime-and-static-bounds/는 게 좋아요.
프로그램에서 살아남은 생활 시간을 나타낸다.근데 그게 아니라생명시간 경계 관련.위탁 국경과도 관련이 있습니까?
static 정보
TBA
궤적 경계 정보
dyn
는 어떤 유형T: Ord + Debug
도 가능하지만'실현T
과Ord
'의 제약을 나타낸다.다중 계승 대신인가요?라이프타임 및 notation
읽기https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html는 게 좋아요.
다음은 컴파일할 수 없습니다.
fn longest(x: &str, y: &str) -> &str {
if x.len() > y.len() {
x
} else {
y
}
}
컴파일할 때 되돌아오는 값이 Debug
인지 x
인지 알 수 없기 때문이다.이하 통과.
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {
y
}
}
y
를 더하면 &'a
와x
모두 같은lifetime를 가지고 있음을 알 수 있다.//편성이 잘못되면 차라리 편성 같은 걸 아무렇게나 붙이는 게 낫지... 그렇게 생각하지만 안 갈 이유도 있는 것 같아요.
// https://stackoverflow.com/questions/31609137/why-are-explicit-lifetimes-needed-in-rust/31612025#31612025
또한
y
에 reference가 있을 때도 Lifetime annotation이 필요하다.struct ImportantExcerpt<'a> {
part: &'a str,
}
fn main() {
let novel = String::from("Call me Ishmael. Some years ago...");
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
let i = ImportantExcerpt {
part: first_sentence,
};
}
lifetime elision 정보
TBA
Struct 및 &self 정보
이것들이 바로 이른바 당의 구조다.
읽기https://doc.rust-lang.org/rust-by-example/fn/methods.html는 게 좋아요.
&mut self
와 &self
는 같다.self: &Self
Caller Object 유형Self
와&mut self
같음문자열이 있는 Struct의 Idigo 정보
다음 내용을 읽을 수 있습니다.이것은 상당히 심원한 문제다.
self: &mut Self
사용 방법은 자신에게 좀 빠르다.바삭바삭하게 조정해야 하는 자리가 아니라면Cow
인가String
인가.Generics 정보
나는 아래를 읽는 것이 비교적 좋다고 말하고 싶지만, 읽어도 잘 모르겠다.
이것은 알기 쉽다.
이 문장도 괜찮은 것 같다.
Reference
이 문제에 관하여(Rust 몰라요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/masatana/articles/413b638a963b54텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)