Back Home

Table of Contents

Deprecation in Rust

To denote a type or function as deprecated in Rust, use the #[deprecated] attribute:

#[deprecated(since="0.1.0", note="Please use stable_fn instead")]
fn deprecated_fn(a: i32) -> i32 {
    1
}

fn stable_fn(a: i32) -> i32 {
    0
}

For more notes, read the rust reference: (Authors 2015)

References

Authors, The Rust. 2015. “The Deprecated Attribute.” 2015. https://doc.rust-lang.org/beta/reference/attributes/diagnostics.html#the-deprecated-attribute.

Deprecation in C/C++

C23/C++14 includes a deprecated attribute that works just like Rust’s:

#include <stdio.h>

[[deprecated]]
void TriassicPeriod(void) {
    puts("Triassic Period: [251.9 - 208.5] million years ago.");
}

[[deprecated("Use NeogenePeriod() instead.")]]
void JurassicPeriod(void) {
    puts("Jurassic Period: [201.3 - 152.1] million years ago.");
}

enum { A [[deprecated]], B [[deprecated("Don't use this field")]] = 2 };

For more notes, read (Reference 2024)

References

Reference, Cpp. 2024. “C++ Attribute: Deprecated.” 2024. https://en.cppreference.com/w/cpp/language/attributes/deprecated.
View history for this file: on Github