git-bug 0.2.4

A rust library for interfacing with git-bug repositories
Documentation
// git-bug-rs - A rust library for interfacing with git-bug repositories
//
// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of git-bug-rs/git-gub.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/agpl.txt>.

use simd_json::{derived::ValueTryIntoString, owned};

use crate::{
    entities::identity::identity_operation::IdentityOperationData,
    replica::entity::operation::operation_data::get,
};

struct SetEmail {
    email: String,
}

pub(crate) fn set_email(
    mut value: owned::Object,
) -> Result<IdentityOperationData, super::decode::Error> {
    let base: SetEmail = SetEmail {
        email: get! {value, "email", try_into_string, super::decode::Error},
    };

    Ok(IdentityOperationData::SetEmail { email: base.email })
}

pub(crate) fn set_email_value(email: &str) -> simd_json::borrowed::Object<'_> {
    let mut object = simd_json::borrowed::Object::new();

    // Safety:
    // We just created this object. As such, it is empty.
    unsafe {
        object.insert_nocheck("email".into(), email.into());
    }

    object
}