C - Derivable Traits

Oxide uses the same derive system as Rust. You can automatically implement common traits with #[derive(...)].

Here are the most commonly derivable traits:

  • Debug - Enables formatting with {:?}
  • Clone - Allows explicit cloning
  • Copy - Allows bitwise copies for simple types
  • Eq / PartialEq - Equality comparisons
  • Ord / PartialOrd - Ordering comparisons
  • Hash - Enables hashing, useful for HashMap keys
  • Default - Provides a default value

Example

#[derive(Debug, Clone, PartialEq, Eq)]
public struct Point {
    public x: Int,
    public y: Int,
}

Not all traits are derivable for all types. For example, Copy requires that all fields are also Copy.