Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: platform value abstraction #805

Merged
merged 20 commits into from
Feb 23, 2023
Merged

Conversation

QuantumExplorer
Copy link
Member

Issue being fixed or feature implemented

This PR removes Cbor Values from RS Drive and replaces them with new "Platform Values" that are more powerful and versatile.

What was done?

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

use crate::Value;

impl Value {
pub fn string_representation(&self) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be implemented std::fmt::Display instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm good point, but I'll do both

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my brother in Christ our APIs are obese with tons of highly specialized methods and spread across multiple files for a one single type, I truly regret that I used impl GroveDb once and now we have large impl Drive and now this type becomes huge; having a standard API is a blessing and with Display you'll have a .to_string() for free, I see not a single reason to have this method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay will remove it from being public then.

/// A representation of a dynamic value that can handled dynamically
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub enum Value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's for the next step, but I would think of introducing the Identifier variant as this one has sometimes a different treatment, especially in terms of displaying (or) serializing.
actually, the concept of the package is similar to the projects I was working on someday ago: https://github.com/qrayven/oxygen/blob/main/src/types/value.rs#L21

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

/// let r_value : u64 = value.as_integer().unwrap();
/// assert_eq!(17, r_value);
/// ```
pub fn as_integer<T>(&self) -> Option<T>
Copy link
Contributor

@fominok fominok Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see many conversions baked into Value type, but how about reducing methods' number and use a trait for it called TryFrom?

For instance, as_ family could be done as TryFrom<&'a Value> for sometype and then sometype::try_from(&value) is available, for owning conversions TryFrom<Value> may be implemented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but I personally felt this was better, because otherwise you would need to type your variables a lot.

Like let a : Option<String> = value.try_from()?
compared to let a = value.get_optional_string()?

I personally prefer the second one, because you have the value, and then you express what you want from it.

I do think though it's probable a good idea to implement try_from's as well.

qrayven
qrayven previously approved these changes Feb 23, 2023
fominok
fominok previously approved these changes Feb 23, 2023
Copy link
Contributor

@fominok fominok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@QuantumExplorer QuantumExplorer dismissed stale reviews from fominok and qrayven via 17ff1b8 February 23, 2023 14:56
@QuantumExplorer QuantumExplorer changed the title feat: value abstraction feat: platform value abstraction Feb 23, 2023
@QuantumExplorer QuantumExplorer merged commit 1abe421 into v0.24-dev Feb 23, 2023
@QuantumExplorer QuantumExplorer deleted the feat/valueAbstraction branch February 23, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants