sass_alt/
ImportsSassCompilerIterator.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/// An iterator over Sass_Import_Entry imports.
6pub struct ImportsSassCompilerIterator
7{
8	length: usize,
9	sass_compiler: *mut Sass_Compiler,
10	next_index: usize,
11}
12
13impl Iterator for ImportsSassCompilerIterator
14{
15	type Item = Sass_Import_Entry;
16	
17	#[inline(always)]
18	fn next(&mut self) -> Option<Self::Item>
19	{
20		if self.next_index == self.length
21		{
22			None
23		}
24		else
25		{
26			let next = self.sass_compiler.get_import(self.next_index);
27			self.next_index += 1;
28			Some(next)
29		}
30	}
31	
32	#[inline(always)]
33	fn size_hint(&self) -> (usize, Option<usize>)
34	{
35		(self.length, Some(self.length))
36	}
37}
38
39impl ExactSizeIterator for ImportsSassCompilerIterator
40{
41	fn len(&self) -> usize
42	{
43		self.length
44	}
45}
46
47impl ImportsSassCompilerIterator
48{
49	#[inline(always)]
50	fn new(sass_compiler: *mut Sass_Compiler) -> Self
51	{
52		Self
53		{
54			length: sass_compiler.get_import_length(),
55			sass_compiler,
56			next_index: 0,
57		}
58	}
59	
60	/// Direct access to last import.
61	/// Returns None if there are no imports.
62	/// If Some, then value is not a null pointer.
63	#[inline(always)]
64	pub fn last_import(&self) -> Option<Sass_Import_Entry>
65	{
66		let pointer = self.sass_compiler.get_import_last();
67		if pointer.is_null()
68		{
69			None
70		}
71		else
72		{
73			Some(pointer)
74		}
75	}
76}