Rust 몰라요.

15354 단어 Rusttech

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로 되돌아오면 된다.boxheap에 있는 메모리의 참조를 나타낸다.참조는 statically-known 사이즈이기 때문에 커뮤니케이터는 용서할 수 있습니다.이거 권투 아니에요?그래서
    Rust는 가능한 한 명확하게 heap에 메모리를 확보하려고 하기 때문에 이런 일을 하려면 Box 키워드를 붙여야 한다.
    https://doc.rust-lang.org/stable/rust-by-example/trait/dyn.html

    dyn 정보


    읽기https://laysakura.github.io/2020/05/21/rust-static-lifetime-and-static-bounds/는 게 좋아요.
    프로그램에서 살아남은 생활 시간을 나타낸다.근데 그게 아니라생명시간 경계 관련.위탁 국경과도 관련이 있습니까?

    static 정보


    TBA

    궤적 경계 정보

    dyn는 어떤 유형T: Ord + Debug도 가능하지만'실현TOrd'의 제약을 나타낸다.다중 계승 대신인가요?

    라이프타임 및 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를 더하면 &'ax 모두 같은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 정보


    다음 내용을 읽을 수 있습니다.이것은 상당히 심원한 문제다.
  • https://users.rust-lang.org/t/idiomatic-string-parmeter-types-str-vs-asref-str-vs-into-string/7934
  • https://qiita.com/Kogia_sima/items/6899c5196813cf231054
  • self: &mut Self 사용 방법은 자신에게 좀 빠르다.바삭바삭하게 조정해야 하는 자리가 아니라면Cow인가String인가.

    Generics 정보


    나는 아래를 읽는 것이 비교적 좋다고 말하고 싶지만, 읽어도 잘 모르겠다.
    https://doc.rust-lang.org/rust-by-example/generics/gen_fn.html
    이것은 알기 쉽다.
    https://doc.rust-jp.rs/book-ja/ch10-00-generics.html
    이 문장도 괜찮은 것 같다.
    https://qiita.com/quasardtm/items/09952838a6ee9582db1d

    좋은 웹페이지 즐겨찾기