사각형 너비와 높이로 면적 구하는 예제에서 struct Rectangcle { width : u32, height : u32, } fn main() { let rect = Rectangcle{ width:20, height:30, }; println!("가로가 {}, 세로가 {}인 사각형의 면적은 {}이다.", rect.width, rect.height, area(rect)); print!("{:?}", rect.width); } fn area(rect : Rectangcle)->u32 { rect.width*rect.height } 위와 같이 만들었더니 소유권 이전이 일어나더라고요. 크기가 정해진 자료형으로만 이루어진 튜플이 Stack에 저장되는 것 처럼 Rectangle 구조체는 크기가 정해진 자료형이라 Stack에 저장될거라고 생각했는데 소유권 이전이 일어나는 걸 보면 Heap에 저장되는 건가 싶어서 질문 드립니다. Stack에 저장되는 자료형은 Copy 되고, Heap에 저장되는 자료형은 소유권 이전이 되는 방식이라고 생각해서 든 의문인데 제가 잘못 알고 있는 부분이 있을까요?? 좋은 강의 잘 듣고 있습니다.
cargo add ... 이후 build는 정상적으로 되는데, cargo lambda build --release --arm64 에서 많은 라인의 error와 함께 컴파일하지 못하네요... 구글링해봐도 잘 모르겠어요 error 마지막 몇라인을 첨부합니다...... error[E0425]: cannot find function drop in this scope --> /.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/race.rs:401:21 | 401 | drop(unsafe { Box::from_raw(ptr) }); | ^^^^ not found in this scope error[E0425]: cannot find function, tuple struct or tuple variant Ok in this scope --> /.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/race.rs:405:13 | 405 | Ok(unsafe { &*ptr }) | ^^ not found in this scope Some errors have detailed explanations: E0405, E0408, E0412, E0425, E0432, E0463, E0531. error: could not compile once_cell (lib) due to 241 previous errors
문자열 리터럴이 뭘 뜻하는지 잘 모르겠어요. 리터럴이 말 그대로 데이터 값 그 자체라고 생각했는데요 (ex 2, 4, "hello") 그런데 강의 중 "문자열 리터럴이 특정 영역에 있는 문자열 데이터를 참조하고 있는 값"이라고 설명하셔서 혼란스러워요. 그럼 문자열 리터럴은 결국 문자열을 가리키고 있는 포인터인가요? let hello: &str = "hello" 그리고 "문자열 리터럴이 특정 영역에 있는 문자열 데이터를 참조하고 있는 값" -> 여기서 특정 영역은 data 영역을 말하는 것일까요? 리터럴이라는 용어 자체가 그냥 데이터 값이라고 알고 있었는데, 리터럴이 참조 값이었고 타입은 문자열 슬라이스 타입이어서 헷갈려요ㅠㅠ 도와주세요
예문을 Integer먼저 넣고 두번째 변수는 String 이게 더 좋지 않을까요? 출처 https://www.reddit.com/r/rust/comments/up1yhg/rust_ownership_for_integer_vs_string_literals/ What’s going on under the covers is that when a variable who’s type has a constant length (like an integer) gets passed to a function, rust allocates space on the call stack for that variable and copies it’s value into the function’s call stack. Thus the instance of X that your function gets is different (is at a different memory address) than the copy of X that was passed to it. For strings, the compiler doesn’t know how much space to allocate (because the function could be called with your constant length string or any other string).