Skip to content

Use Non-Nil Ref Type #581

@krakow10

Description

@krakow10

If a new type was added, say SomeRef(NonZeroU128), a lot of strange edge cases jump out such as #517. WeakDom::transfer should also be able to transfer to dest_parent = Ref::none(), but it's not obvious without this new type. The type can also be used within Ref(Option<SomeRef>) as the inner type and for Content::Object(SomeRef) since the Roblox documentation for Content states that Content::Object always contains a non-nil ref. Perhaps the naming should be reversed, the current Ref should be renamed to OptionalRef and SomeRef becomes simply Ref.

Here is the primary example that shows that this is a more accurate data model:
before:

if parent_ref.is_some() {
    let parent = self.instances.get_mut(&parent_ref).unwrap();

after:

if let Some(parent_some_ref) = parent_ref.to_some() {
    let parent = self.instances.get_mut(&parent_some_ref).unwrap();

I have three pull requests implementing this in stages:

  1. SomeRef Part 1: Introduce SomeRef #584
  2. SomeRef Part 2: Use SomeRef Internally #585 Use SomeRef type internally, with minimal public interface changes
  • every new if statement is a case that was previously unhandled
  • WeakDom::from_raw, into_raw expose the new inner types
  • ContentType::Object exposes the new inner type
  • instance.children() -> &[Ref] must transmute using unsafe
  1. SomeRef Part 3 v1: Use SomeRef Externally #586 Refactor public interface to use SomeRef where appropriate
  • instance.referent() -> SomeRef
  • instance.parent() -> Option<SomeRef>
  • instance.children() -> &[SomeRef]
  • dom.root_ref() -> Option<SomeRef>
  • dom.get_by_ref(referent: SomeRef) -> Option<&Instance>
  • dom.insert(parent_ref: impl Into<OptionalRef>, root_builder: InstanceBuilder) -> SomeRef
  • and many more

And one that goes directly to the endgame:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions