sass_alt/values/
MapSassValue.rs

1// This file is part of sass-alt. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/sass-alt/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of sass-alt. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/sass-alt/master/COPYRIGHT.
3
4
5/// A Sass_Value typed as a known map.
6/// Note that these are not real maps. They are actually just vectors of (Key, Value) pairs, and the Key can be duplicated.
7#[derive(Debug, Copy, Clone)]
8pub struct MapSassValue<'a>
9{
10	reference: &'a SassValue,
11}
12
13impl<'a> MapSassValue<'a>
14{
15	/// Is empty.
16	#[inline(always)]
17	pub fn is_empty(&self) -> bool
18	{
19		self.length() == 0
20	}
21	
22	/// Get length.
23	#[inline(always)]
24	pub fn length(&self) -> usize
25	{
26		unsafe { sass_map_get_length(self.reference.0 as *const _) }
27	}
28	
29	/// Get key.
30	/// There is no bounds check.
31	#[inline(always)]
32	pub unsafe fn get_key_unchecked(&self, index: usize) -> SassValue
33	{
34		let pointer = sass_map_get_key(self.reference.0 as *const _, index);
35		SassValue(pointer, self.reference.is_owned_by_rust())
36	}
37	
38	/// Set key.
39	/// There is no bounds check.
40	#[inline(always)]
41	pub unsafe fn set_key_unchecked(&self, index: usize, key: SassValue)
42	{
43		sass_map_set_key(self.reference.0, index, key.transfer_ownership_to_c())
44	}
45	
46	/// Get value.
47	/// There is no bounds check.
48	#[inline(always)]
49	pub unsafe fn get_value_unchecked(&self, index: usize) -> SassValue
50	{
51		let pointer = sass_map_get_value(self.reference.0 as *const _, index);
52		SassValue(pointer, self.reference.is_owned_by_rust())
53	}
54	
55	/// Set value.
56	/// There is no bounds check.
57	#[inline(always)]
58	pub unsafe fn set_value_unchecked(&self, index: usize, value: SassValue)
59	{
60		sass_map_set_value(self.reference.0, index, value.transfer_ownership_to_c())
61	}
62	
63	/// Iterator over (key, value) pairs.
64	#[inline(always)]
65	pub fn iter(&self) -> MapSassValueIterator<'a>
66	{
67		MapSassValueIterator::new(*self)
68	}
69	
70	/// Iterator over keys.
71	#[inline(always)]
72	pub fn iter_keys(&self) -> KeyMapSassValueIterator<'a>
73	{
74		KeyMapSassValueIterator::new(*self)
75	}
76	
77	/// Iterator over values.
78	#[inline(always)]
79	pub fn iter_values(&self) -> ValueMapSassValueIterator<'a>
80	{
81		ValueMapSassValueIterator::new(*self)
82	}
83}
84
85impl<'a> IntoIterator for MapSassValue<'a>
86{
87	type Item = (SassValue, SassValue);
88	
89	type IntoIter = MapSassValueIterator<'a>;
90	
91	#[inline(always)]
92	fn into_iter(self) -> Self::IntoIter
93	{
94		MapSassValueIterator::new(self)
95	}
96}