Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Zeeshan Ali
gstreamer-rs
Commits
999c84f0
Commit
999c84f0
authored
Aug 10, 2018
by
Sebastian Dröge
🍵
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement ValueExt::compare() around std::cmp::Ordering and implement an eq() function
No need for a custom enum
parent
dba110e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
44 deletions
+17
-44
gstreamer/src/value.rs
gstreamer/src/value.rs
+17
-44
No files found.
gstreamer/src/value.rs
View file @
999c84f0
...
...
@@ -8,14 +8,13 @@
use
num_rational
::
Rational32
;
use
std
::
borrow
::{
Borrow
,
Cow
};
use
std
::
cmp
;
use
std
::
fmt
;
use
std
::
ops
;
use
std
::
slice
;
use
glib
;
use
glib
::
translate
::{
from_glib
,
from_glib_full
,
FromGlib
,
ToGlib
,
ToGlibPtr
,
ToGlibPtrMut
,
Uninitialized
,
};
use
glib
::
translate
::{
from_glib
,
from_glib_full
,
ToGlibPtr
,
ToGlibPtrMut
,
Uninitialized
};
use
glib
::
value
::{
FromValue
,
FromValueOptional
,
SetValue
,
ToSendValue
,
Value
};
use
ffi
;
...
...
@@ -673,44 +672,10 @@ impl<'a> glib::types::StaticType for List<'a> {
}
}
#[derive(PartialEq,
Eq,
Copy,
Clone,
Debug,
Hash)]
pub
enum
ValueOrder
{
LessThan
,
Equal
,
GreaterThan
,
Unordered
,
}
impl
ToGlib
for
ValueOrder
{
type
GlibType
=
i32
;
fn
to_glib
(
&
self
)
->
Self
::
GlibType
{
match
*
self
{
ValueOrder
::
LessThan
=>
ffi
::
GST_VALUE_LESS_THAN
,
ValueOrder
::
Equal
=>
ffi
::
GST_VALUE_EQUAL
,
ValueOrder
::
GreaterThan
=>
ffi
::
GST_VALUE_GREATER_THAN
,
ValueOrder
::
Unordered
=>
ffi
::
GST_VALUE_UNORDERED
,
}
}
}
impl
FromGlib
<
i32
>
for
ValueOrder
{
fn
from_glib
(
v
:
i32
)
->
Self
{
skip_assert_initialized!
();
match
v
{
ffi
::
GST_VALUE_LESS_THAN
=>
ValueOrder
::
LessThan
,
ffi
::
GST_VALUE_EQUAL
=>
ValueOrder
::
Equal
,
ffi
::
GST_VALUE_GREATER_THAN
=>
ValueOrder
::
GreaterThan
,
ffi
::
GST_VALUE_UNORDERED
=>
ValueOrder
::
Unordered
,
_
=>
unreachable!
(),
}
}
}
pub
trait
GstValueExt
:
Sized
{
fn
can_compare
(
&
self
,
other
:
&
Self
)
->
bool
;
fn
compare
(
&
self
,
other
:
&
Self
)
->
ValueOrder
;
fn
compare
(
&
self
,
other
:
&
Self
)
->
Option
<
cmp
::
Ordering
>
;
fn
eq
(
&
self
,
other
:
&
Self
)
->
bool
;
fn
can_intersect
(
&
self
,
other
:
&
Self
)
->
bool
;
fn
intersect
(
&
self
,
other
:
&
Self
)
->
Option
<
Self
>
;
fn
can_subtract
(
&
self
,
other
:
&
Self
)
->
bool
;
...
...
@@ -734,15 +699,23 @@ impl GstValueExt for glib::Value {
}
}
fn
compare
(
&
self
,
other
:
&
Self
)
->
Value
Order
{
fn
compare
(
&
self
,
other
:
&
Self
)
->
Option
<
cmp
::
Order
ing
>
{
unsafe
{
from_glib
(
ffi
::
gst_value_compare
(
self
.to_glib_none
()
.0
,
other
.to_glib_none
()
.0
,
))
let
val
=
ffi
::
gst_value_compare
(
self
.to_glib_none
()
.0
,
other
.to_glib_none
()
.0
);
match
val
{
ffi
::
GST_VALUE_LESS_THAN
=>
Some
(
cmp
::
Ordering
::
Less
),
ffi
::
GST_VALUE_EQUAL
=>
Some
(
cmp
::
Ordering
::
Equal
),
ffi
::
GST_VALUE_GREATER_THAN
=>
Some
(
cmp
::
Ordering
::
Greater
),
_
=>
None
,
}
}
}
fn
eq
(
&
self
,
other
:
&
Self
)
->
bool
{
self
.compare
(
other
)
==
Some
(
cmp
::
Ordering
::
Equal
)
}
fn
can_intersect
(
&
self
,
other
:
&
Self
)
->
bool
{
unsafe
{
from_glib
(
ffi
::
gst_value_can_intersect
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment