pub struct JsonObject { /* private fields */ }Expand description
A minimal single-object JSON builder for --format=json on the
mutating commands (commit, push, pull, fetch, merge,
cherry-pick, revert, rebase, stash, tag, verify-attest):
each invocation emits exactly one JSON object to stdout describing
the outcome, unlike log/branch’s per-record JSONL streaming.
Keeps the same hand-rolled-escaping approach as the rest of this
module (json_escape) rather than pulling serde_json into the
CLI’s presentation layer — see branch.rs/log.rs for the
precedent this mirrors. Fields are written in insertion order, so
callers should add them in a fixed, documented order to keep output
deterministic and snapshot-friendly.
Implementations§
Source§impl JsonObject
impl JsonObject
pub fn new() -> Self
Sourcepub fn field_str(&mut self, key: &str, value: &str) -> &mut Self
pub fn field_str(&mut self, key: &str, value: &str) -> &mut Self
Append "<key>":"<escaped value>".
Sourcepub fn field_hash(&mut self, key: &str, h: &Hash) -> &mut Self
pub fn field_hash(&mut self, key: &str, h: &Hash) -> &mut Self
Append "<key>":<hash-as-64-hex-string>".
Sourcepub fn field_opt_hash(&mut self, key: &str, h: Option<&Hash>) -> &mut Self
pub fn field_opt_hash(&mut self, key: &str, h: Option<&Hash>) -> &mut Self
Append "<key>":null when h is None, else the hex hash.
Sourcepub fn field_opt_str(&mut self, key: &str, s: Option<&str>) -> &mut Self
pub fn field_opt_str(&mut self, key: &str, s: Option<&str>) -> &mut Self
Append "<key>":null when s is None, else the escaped string.
Sourcepub fn field_bool(&mut self, key: &str, v: bool) -> &mut Self
pub fn field_bool(&mut self, key: &str, v: bool) -> &mut Self
Append "<key>":true/"<key>":false.
Trait Implementations§
Source§impl Debug for JsonObject
impl Debug for JsonObject
Source§impl Default for JsonObject
impl Default for JsonObject
Source§fn default() -> JsonObject
fn default() -> JsonObject
Auto Trait Implementations§
impl Freeze for JsonObject
impl RefUnwindSafe for JsonObject
impl Send for JsonObject
impl Sync for JsonObject
impl Unpin for JsonObject
impl UnsafeUnpin for JsonObject
impl UnwindSafe for JsonObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more