Skip to main content

brows3r_lib/path/
mod.rs

1//! Path domain types: `S3Location` and `DisplayPath`.
2//!
3//! `S3Location` is the canonical "where am I" domain type consumed by every
4//! other module. `DisplayPath` is the breadcrumb-friendly view shown in the
5//! UI. Encoding between these forms and external URI/clipboard strings lives
6//! in `encode`.
7//!
8//! # OCP contract
9//! - `S3Location` is the stable domain type — adding a field (e.g. `version_id`)
10//!   is non-breaking.
11//! - No other module should percent-encode keys; all encoding is centralised in
12//!   `path::encode`.
13//! - Three explicit views: canonical (`brows3r://`), display, and clipboard
14//!   (`s3://`). Future views (presigned URL, CloudFront URL) are new functions
15//!   in `encode`.
16
17pub mod encode;
18
19use serde::{Deserialize, Serialize};
20
21use crate::ids::{BucketId, ObjectKey, ProfileId};
22
23// ---------------------------------------------------------------------------
24// S3Location
25// ---------------------------------------------------------------------------
26
27/// The canonical domain type for "where am I in S3".
28///
29/// `profile_id` is the stable internal identifier (UUID v4); it is used in
30/// canonical URIs so that two profiles with the same display name remain
31/// unambiguous (AC-2).
32///
33/// `prefix` is the current directory prefix (empty string = bucket root).
34/// `key` is `Some` when a specific object is referenced, `None` for a prefix
35/// (directory) location.
36#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
37pub struct S3Location {
38    pub profile_id: ProfileId,
39    pub bucket: BucketId,
40    /// Current prefix (virtual directory). Empty string means bucket root.
41    pub prefix: String,
42    /// Specific object key. `None` when the location refers to a prefix.
43    pub key: Option<ObjectKey>,
44}
45
46// ---------------------------------------------------------------------------
47// DisplayPath
48// ---------------------------------------------------------------------------
49
50/// Breadcrumb-friendly view of an `S3Location`.
51///
52/// `profile_display_name` is the human-readable profile label shown as the
53/// root breadcrumb segment. `bucket` is the raw bucket name. `segments` are
54/// the individual prefix/key path components, split on `/` with empty strings
55/// removed, suitable for rendering as clickable breadcrumb items.
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57pub struct DisplayPath {
58    pub profile_display_name: String,
59    pub bucket: String,
60    pub segments: Vec<String>,
61}