nautilus_core/column/marker.rs
1//! `ColumnMarker` — lightweight owned column identifier.
2
3/// A lightweight column identifier for use in selection descriptors.
4///
5/// Stores owned `String` fields so callers can construct markers from
6/// dynamic (runtime) data without resorting to `Box::leak`.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct ColumnMarker {
9 /// Table name.
10 pub table: String,
11 /// Column name.
12 pub name: String,
13}
14
15impl ColumnMarker {
16 /// Create a new column marker.
17 ///
18 /// Accepts any type that implements `Into<String>`, so both
19 /// `&str` literals and owned `String` values work without ceremony.
20 pub fn new(table: impl Into<String>, name: impl Into<String>) -> Self {
21 Self {
22 table: table.into(),
23 name: name.into(),
24 }
25 }
26
27 /// Returns the join-safe alias for this column.
28 ///
29 /// The alias uses the format "table__column" which is safe to use
30 /// in queries with joins, preventing column name conflicts.
31 ///
32 /// # Example
33 ///
34 /// ```
35 /// use nautilus_core::ColumnMarker;
36 ///
37 /// let marker = ColumnMarker::new("users", "id");
38 /// assert_eq!(marker.alias(), "users__id");
39 /// ```
40 pub fn alias(&self) -> String {
41 format!("{}__{}", self.table, self.name)
42 }
43}