Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::OsFilename Class Reference

#include <os-filename.hh>

Public Member Functions

const std::filesystem::path & path () const noexcept
const std::filesystem::path::value_type * c_str () const noexcept
auto operator<=> (const OsFilename &) const =default

Static Public Member Functions

static OsFilename fromPathAsserting (std::filesystem::path p)
static OsFilename fromPathThrowing (std::filesystem::path p)

Friends

class OsCanonPath

Detailed Description

A newtype around std::filesystem::path that asserts at construction time that the path is a single filename component.

A valid OsFilename:

  • Has no root path or root name (no drive letter on Windows, no leading /)
  • Has no directory separators
  • Is not empty
  • Is not . or ..

This type is useful for APIs that expect a bare filename rather than a full path, providing compile-time documentation and runtime validation.

Member Function Documentation

◆ fromPathAsserting()

OsFilename nix::OsFilename::fromPathAsserting ( std::filesystem::path p)
inlinestatic

Construct an OsFilename from a path, asserting that it is a single filename component.

Use this when we are witnessing an internal invariant / we as the programmer know the validation should pass. Fails with an assertion otherwise.

◆ fromPathThrowing()

OsFilename nix::OsFilename::fromPathThrowing ( std::filesystem::path p)
static

Construct an OsFilename from a path, throwing an Error if it is not a single filename component.

Use this when the input comes from users / the external world, and we are not sure whether the invariant will pass.


The documentation for this class was generated from the following files: