Associated constant with anonymous generic type
⚓ Rust 📅 2025-10-28 👤 surdeus 👁️ 2I have this trait:
use std::path::Path;
/// Trait for types with a default file path.
pub trait DefaultFile {
/// The type of the default file path.
type DefaultFile: AsRef<Path>;
/// The default file path.
const DEFAULT_FILE: Self::DefaultFile;
}
I find this definition and subsequent usage a bit verbose.
However, I could not get anything like this to work:
use std::path::Path;
/// Trait for types with a default file path.
pub trait DefaultFile {
/// The default file path.
const DEFAULT_FILE: impl AsRef<Path>;
}
Is there a short-hand for this kind of definition?
3 posts - 3 participants
🏷️ Rust_feed