pub struct RawDoc {
pub payload: BTreeMap<PayloadId, Payload>,
pub delegates: Vec<Did>,
pub threshold: usize,
pub visibility: Visibility,
/* private fields */
}
Expand description
RawDoc
is similar to the Doc
type, however, it can be edited and may
not be valid.
It is expected that any changes to a Doc
are made via RawDoc
, and
then verified by using RawDoc::verified
.
Note that RawDoc
only implements Deserialize
. This prevents us from
serializing an unverified document, while also making sure that any document
that is deserialized is verified.
Fields§
§payload: BTreeMap<PayloadId, Payload>
The payload section.
delegates: Vec<Did>
The delegates section.
threshold: usize
The signature threshold.
visibility: Visibility
Repository visibility.
Implementations§
Source§impl RawDoc
impl RawDoc
Sourcepub fn new(
project: Project,
delegates: Vec<Did>,
threshold: usize,
visibility: Visibility,
) -> RawDoc
pub fn new( project: Project, delegates: Vec<Did>, threshold: usize, visibility: Visibility, ) -> RawDoc
Construct a new RawDoc
with an initial RawDoc::payload
containing the provided Project
, and the given delegates
,
threshold
, and visibility
.
Sourcepub fn project(&self) -> Result<Project, PayloadError>
pub fn project(&self) -> Result<Project, PayloadError>
Get the project payload, if it exists and is valid, out of this document.
Sourcepub fn is_delegate(&self, did: &Did) -> bool
pub fn is_delegate(&self, did: &Did) -> bool
Check if the given did
is in the set of RawDoc::delegates
.
Sourcepub fn delegate(&mut self, did: Did)
pub fn delegate(&mut self, did: Did)
Add a new delegate to the document.
Note that if this Did
is a duplicate, then the resulting set will only
show it once.
Sourcepub fn rescind(&mut self, did: &Did) -> Result<bool, DocError>
pub fn rescind(&mut self, did: &Did) -> Result<bool, DocError>
Remove the did
from the set of delegates. Returns true
if it was
removed.
Sourcepub fn from_json(bytes: &[u8]) -> Result<RawDoc, DocError>
pub fn from_json(bytes: &[u8]) -> Result<RawDoc, DocError>
Construct the RawDoc
from the set of bytes
that are expected to be
in JSON format.
Sourcepub fn verified(self) -> Result<Doc, DocError>
pub fn verified(self) -> Result<Doc, DocError>
Verify the RawDoc
’s values, converting it into a valid Doc
.
The verifications are as follows:
RawDoc::delegates
: any duplicates are removed, and for the remaining set ensure that it is non-empty and does not exceed a length ofMAX_DELEGATES
.RawDoc::threshold
: ensure that it is in the range[1, delegates.len()]
.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RawDoc
impl<'de> Deserialize<'de> for RawDoc
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<RawDoc, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<RawDoc, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl GetCanonicalRefs for RawDoc
impl GetCanonicalRefs for RawDoc
type Error = CanonicalRefsError
Source§fn canonical_refs(
&self,
) -> Result<Option<CanonicalRefs>, <RawDoc as GetCanonicalRefs>::Error>
fn canonical_refs( &self, ) -> Result<Option<CanonicalRefs>, <RawDoc as GetCanonicalRefs>::Error>
CanonicalRefs
, returning Some
if they are not
present, and None
if they are missing. Read moreSource§fn raw_canonical_refs(
&self,
) -> Result<Option<RawCanonicalRefs>, <RawDoc as GetCanonicalRefs>::Error>
fn raw_canonical_refs( &self, ) -> Result<Option<RawCanonicalRefs>, <RawDoc as GetCanonicalRefs>::Error>
RawCanonicalRefs
, returning Some
if they are not
present, and None
if they are missing. Read moreSource§fn canonical_refs_or_default<D, E>(
&self,
default: D,
) -> Result<CanonicalRefs, E>
fn canonical_refs_or_default<D, E>( &self, default: D, ) -> Result<CanonicalRefs, E>
CanonicalRefs
, and in the case of None
, then use the
default
function to return a default set of CanonicalRefs
.impl Eq for RawDoc
impl StructuralPartialEq for RawDoc
Auto Trait Implementations§
impl Freeze for RawDoc
impl RefUnwindSafe for RawDoc
impl Send for RawDoc
impl Sync for RawDoc
impl Unpin for RawDoc
impl UnwindSafe for RawDoc
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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