GunCore

Struct GunCore 

Source
pub struct GunCore {
    pub graph: Arc<Graph>,
    pub state: Arc<State>,
    pub events: Arc<EventEmitter>,
    pub storage: Option<Arc<dyn Storage>>,
    pub id_counter: Arc<AtomicU64>,
    pub dup: Arc<RwLock<Dup>>,
}
Expand description

Core Gun instance structure

This is the central engine that powers all Gun operations. It manages:

  • Graph: In-memory storage of all nodes
  • State: Timestamp generation for conflict resolution
  • Events: Event system for reactive updates
  • Storage: Optional persistent storage backend
  • Dedup: Message deduplication for network operations

Based on Gun.js root.js and core.js. This is an internal structure that is wrapped by the public Gun type.

§Example

use gun::core::GunCore;

let core = GunCore::new();
let soul = core.uuid(None);
println!("Generated soul: {}", soul);

Fields§

§graph: Arc<Graph>§state: Arc<State>§events: Arc<EventEmitter>§storage: Option<Arc<dyn Storage>>§id_counter: Arc<AtomicU64>§dup: Arc<RwLock<Dup>>

Implementations§

Source§

impl GunCore

Source

pub fn new() -> Self

Create a new GunCore instance without persistent storage

This creates an in-memory only instance. Use with_storage to enable persistent storage.

§Returns

A new GunCore instance with no persistent storage.

Source

pub fn with_storage(storage: Arc<dyn Storage>) -> Self

Create a new GunCore instance with persistent storage

This enables data persistence across application restarts. The storage backend can be any implementation of the Storage trait, such as LocalStorage or SledStorage.

§Arguments
  • storage - Storage backend implementing the Storage trait
§Returns

A new GunCore instance with persistent storage enabled.

§Example
use gun::core::GunCore;
use gun::storage::LocalStorage;
use std::sync::Arc;

let storage = Arc::new(LocalStorage::new("./gun_data")?);
let core = GunCore::with_storage(storage);
Source

pub fn uuid(&self, length: Option<usize>) -> String

Generate a new soul (UUID) for a node

Souls are unique identifiers for nodes in the Gun graph. They combine:

  • A state-based component derived from the current timestamp
  • A random component for uniqueness

Based on Gun.js uuid generation: Gun.state().toString(36).replace('.','') + String.random(12)

§Arguments
  • length - Optional length of the random component (default: 12)
§Returns

A unique soul string suitable for use as a node identifier.

§Example
use gun::core::GunCore;

let core = GunCore::new();
let soul = core.uuid(None); // Default 12-character random suffix
let short_soul = core.uuid(Some(6)); // 6-character random suffix
Source

pub fn random_id(&self, length: usize) -> String

Generate a simple random ID (for message IDs, etc.)

This generates a pure random alphanumeric string without the state component. Useful for message IDs and other temporary identifiers.

§Arguments
  • length - Length of the random ID to generate
§Returns

A random alphanumeric string of the specified length.

§Example
use gun::core::GunCore;

let core = GunCore::new();
let message_id = core.random_id(16);
Source

pub fn next_chain_id(&self) -> u64

Get the next unique chain ID

Chain IDs are used internally to track chain instances for listener management. This increments atomically and returns a unique identifier for each chain.

§Returns

A unique chain ID (monotonically increasing counter).

Trait Implementations§

Source§

impl Default for GunCore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more