From b9f3681728185d12265d0a35d327db00496b3ea7 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Mon, 18 Jun 2018 14:52:16 -0700 Subject: [PATCH] Part 2: Allow to Deref StructuredMap to the underlying IndexMap. Again, this is a fundamental Rust pattern for newtypes. It's awfully hard to actually use `StructuredMap` without it! --- core/src/types.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/types.rs b/core/src/types.rs index 7efc26f2..15aec5ee 100644 --- a/core/src/types.rs +++ b/core/src/types.rs @@ -15,6 +15,11 @@ use ::std::convert::{ use ::std::ffi::{ CString, }; + +use ::std::ops::{ + Deref, +}; + use ::std::os::raw::c_char; use ::std::rc::{ @@ -342,6 +347,14 @@ impl Binding { #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct StructuredMap(pub IndexMap, Binding>); +impl Deref for StructuredMap { + type Target = IndexMap, Binding>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl StructuredMap { pub fn insert(&mut self, name: N, value: B) where N: Into>, B: Into { self.0.insert(name.into(), value.into());