Change constructor in bindings

This commit is contained in:
Jazz Turner-Baggs 2026-02-18 20:29:55 -08:00
parent 53597bc501
commit 459ce2802c
No known key found for this signature in database
11 changed files with 1991 additions and 24 deletions

View File

@ -49,8 +49,8 @@ pub struct ContextHandle(pub(crate) Context);
/// # Returns
/// Opaque handle to the store. Must be freed with destroy_context()
#[ffi_export]
pub fn create_context() -> repr_c::Box<ContextHandle> {
Box::new(ContextHandle(Context::new())).into()
pub fn create_context(name: String) -> repr_c::Box<ContextHandle> {
Box::new(ContextHandle(Context::new_with_name(name))).into()
}
/// Destroys a conversation store and frees its memory

View File

@ -21,16 +21,6 @@ pub struct Context {
}
impl Context {
pub fn new() -> Self {
let identity = Rc::new(Identity::default());
let inbox = Inbox::new(Rc::clone(&identity)); //
Self {
_identity: identity,
store: ConversationStore::new(),
inbox,
}
}
pub fn new_with_name(name: impl Into<String>) -> Self {
let identity = Rc::new(Identity::new(name));
let inbox = Inbox::new(Rc::clone(&identity)); //
@ -170,8 +160,8 @@ mod tests {
#[test]
fn ctx_integration() {
let mut saro = Context::new();
let mut raya = Context::new();
let mut saro = Context::new_with_name("saro");
let mut raya = Context::new_with_name("raya");
// Raya creates intro bundle and sends to Saro
let bundle = raya.create_intro_bundle().unwrap();

View File

@ -36,7 +36,7 @@ impl Identity {
// Names are a friendly developer chosen identifier for an Identity which
// can provide between logging.
pub fn get_name(&self) -> &str {
return &self.name;
&self.name
}
}

View File

@ -238,10 +238,10 @@ mod tests {
#[test]
fn test_invite_privatev1_roundtrip() {
let saro_ident = Identity::new();
let saro_ident = Identity::new("saro");
let saro_inbox = Inbox::new(saro_ident.into());
let raya_ident = Identity::new();
let raya_ident = Identity::new("raya");
let mut raya_inbox = Inbox::new(raya_ident.into());
let bundle = raya_inbox.create_intro_bundle();

View File

@ -21,8 +21,8 @@ mod tests {
#[test]
fn test_message_roundtrip() {
let mut saro = create_context();
let mut raya = create_context();
let mut saro = create_context("saro".into());
let mut raya = create_context("raya".into());
// Raya Creates Bundle and Sends to Saro
let intro_result = create_intro_bundle(&mut raya);

3
nim-bindings/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
nimble.develop
nimble.paths
nimbledeps

4
nim-bindings/config.nims Normal file
View File

@ -0,0 +1,4 @@
# begin Nimble config (version 2)
when withDir(thisDir(), system.fileExists("nimble.paths")):
include "nimble.paths"
# end Nimble config

View File

@ -15,8 +15,8 @@ proc encode*(s: string): seq[byte] =
proc pingpong() =
var raya = newConversationsContext()
var saro = newConversationsContext()
var raya = newConversationsContext("raya")
var saro = newConversationsContext("saro")
# Perform out of band Introduction

1970
nim-bindings/specs Normal file

File diff suppressed because one or more lines are too long

View File

@ -97,7 +97,7 @@ type
## Creates a new libchat Context
## Returns: Opaque handle to the context. Must be freed with destroy_context()
proc create_context*(): ContextHandle {.importc, dynlib: CONVERSATIONS_LIB.}
proc create_context*(name: ReprCString): ContextHandle {.importc, dynlib: CONVERSATIONS_LIB.}
## Destroys a context and frees its memory
## - handle must be a valid pointer from create_context()

View File

@ -13,9 +13,9 @@ type
data*: seq[uint8]
## Create a new conversations context
proc newConversationsContext*(): LibChat =
proc newConversationsContext*(name: string): LibChat =
result.handle = create_context()
result.handle = create_context(name.toReprCString)
result.buffer_size = 256
if result.handle.isNil:
raise newException(IOError, "Failed to create context")