docs

v0.1.2 문서를 보고 있습니다. 이 버전은 더 이상 지원하지 않습니다. 최신 릴리스: v0.1.3 →

#E0092: 직접 부른 Drop::drop

drop은 using 블록이 끝날 때 저절로 돌며, 다시 부르면 자원을 두 번 해제합니다. 일찍 해제하려면 close() 같은 메서드를 따로 두세요.

nabi
struct Conn { id: i32; }
impl Drop for Conn { fn drop(ref self) {} }

let c = Conn { id: 1 };
c.drop();
error[E0092]: `Drop::drop` cannot be called directly; it runs when a `using` block exits - expose a method such as `close()` to release early
  --> main.nabi:5:1
   |
 5 | c.drop();
   | ^^^^^^^^

값의 해제는 using에 맡기세요.

nabi
struct Conn { id: i32; }
impl Drop for Conn { fn drop(ref self) { println(f"closed {self.id}"); } }

using c = (Conn { id: 1 }) {
    println(f"using {c.id}");
}
using 1
closed 1

관련 코드: E0066 Drop 없는 값의 using, E0133 옮기거나 닫은 뒤에 쓴 자원

잘못된 곳이 있나요? GitHub에서 이 페이지 고치기. 마지막 수정