Skip to content

Commit fe7a8a4

Browse files
committed
Rollup merge of rust-lang#28048 - steveklabnik:doc_unimplemented, r=alexcrichton
2 parents 4b1967c + 59653c1 commit fe7a8a4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/libcore/macros.rs

+45
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,51 @@ macro_rules! unreachable {
254254

255255
/// A standardised placeholder for marking unfinished code. It panics with the
256256
/// message `"not yet implemented"` when executed.
257+
///
258+
/// This can be useful if you are prototyping and are just looking to have your
259+
/// code typecheck, or if you're implementing a trait that requires multiple
260+
/// methods, and you're only planning on using one of them.
261+
///
262+
/// # Examples
263+
///
264+
/// Here's an example of some in-progress code. We have a trait `Foo`:
265+
///
266+
/// ```
267+
/// trait Foo {
268+
/// fn bar(&self);
269+
/// fn baz(&self);
270+
/// }
271+
/// ```
272+
///
273+
/// We want to implement `Foo` on one of our types, but we also want to work on
274+
/// just `bar()` first. In order for our code to compile, we need to implement
275+
/// `baz()`, so we can use `unimplemented!`:
276+
///
277+
/// ```
278+
/// # trait Foo {
279+
/// # fn foo(&self);
280+
/// # fn bar(&self);
281+
/// # }
282+
/// struct MyStruct;
283+
///
284+
/// impl Foo for MyStruct {
285+
/// fn foo(&self) {
286+
/// // implementation goes here
287+
/// }
288+
///
289+
/// fn bar(&self) {
290+
/// // let's not worry about implementing bar() for now
291+
/// unimplemented!();
292+
/// }
293+
/// }
294+
///
295+
/// fn main() {
296+
/// let s = MyStruct;
297+
/// s.foo();
298+
///
299+
/// // we aren't even using bar() yet, so this is fine.
300+
/// }
301+
/// ```
257302
#[macro_export]
258303
#[unstable(feature = "core",
259304
reason = "relationship with panic is unclear")]

0 commit comments

Comments
 (0)