sdp: Use .ok() instead of manual match on Ok and Err

Using `.ok()` is more concise when loosing error context in favour of a
simple `None` value.

Automatic replacement SSR pattern in rust-analyzer:

    {let $a = $b;match $c {Ok($d) => Some($e), Err(_) => None }} ==>> {$b.ok()}

Note that rust-analyzer does not support:
- duplicate labels (ie. $c should be equal to $a, and $e equal to $d);
- statement lists yet, hence both sides are wrapped in braces.

But it performs the desired operation well enough here.
This commit is contained in:
Marijn Suijten 2021-01-07 22:49:11 +01:00
parent 15505cc5b8
commit f4ad451956
2 changed files with 14 additions and 70 deletions

View file

@ -228,11 +228,7 @@ impl SDPMediaRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -243,11 +239,7 @@ impl SDPMediaRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -296,11 +288,7 @@ impl SDPMediaRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -311,11 +299,7 @@ impl SDPMediaRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -337,11 +321,7 @@ impl SDPMediaRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -360,11 +340,7 @@ impl SDPMediaRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}

View file

@ -266,11 +266,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -281,11 +277,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -326,11 +318,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -341,11 +329,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -412,11 +396,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -427,11 +407,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -457,11 +433,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}
@ -472,11 +444,7 @@ impl SDPMessageRef {
if ptr.is_null() {
None
} else {
let result = CStr::from_ptr(ptr).to_str();
match result {
Ok(attr) => Some(attr),
Err(_) => None,
}
CStr::from_ptr(ptr).to_str().ok()
}
}
}