Comprehensive Rust Ch.16.2 – pattern matching for structs using capture and const expressions

Having trouble understanding the second speaker note point in the Pattern Matching – Destructuring structs of the Comprehensive Rust by Google. Here is the sample code. struct Foo { x: (u32, u32), y: u32, } #[rustfmt::skip] fn main() { let foo = Foo { x: (1, 2), y: 3 }; match foo { Foo {… Read More Comprehensive Rust Ch.16.2 – pattern matching for structs using capture and const expressions

Replace All numeric substring with character

I have to replace all digit patterns with some character. For 1 digit its working fine for e.g for given string ramesh_gone_to_avbp_9_vc.pdf its working fine changing it to ramesh_gone_to_avbp_*_vc.pdf but for given input ramesh_gone_to_avbp_91_vc.pdf its changing to ramesh_gone_to_avbp_**_vc.pdf but i want output like ramesh_gone_to_avbp_*_vc.pdf This is what i tried so far String ss = "ramesh_gone_to_avbp_92_vc.pdf";… Read More Replace All numeric substring with character

How to handle to read a column and cast to Option[String] from postgre db which has null and string values in Scala 2?

I had a problem with null data coming from one of the postgre db tables. In my situation, I have a column that is nullable which means it stores originally varchar data but has also null values for some rows. I read that column as Any data type inside Scala 2. My first problem was… Read More How to handle to read a column and cast to Option[String] from postgre db which has null and string values in Scala 2?

Is `if let` just another way of writing other `if` statements?

So I’m learning Rust and I’m learning about pattern matching and "if let" statements as alternatives to matching expressions. I was watching this video regarding "if let" which is mentioned at 11:00 and they give this example: fn main() { let some_value: Option<i32> = Some(3); if let Some(3) = some_value { println!("three"); } } I… Read More Is `if let` just another way of writing other `if` statements?

inconsistent non-exhaustive pattern matching with if statements

I’ve wrote two equivalent functions in Rust, one compiles the other doesn’t. Program 1: pub fn majority_element<T: Eq>(nums: &[T]) -> Option<&T> { nums.iter().fold(None, |acc, curr| { match acc { None => Some((1, curr)), Some((0, prev)) if prev != curr => Some((1, curr)), Some((count, prev)) => Some((count + if prev == curr { 1 } else… Read More inconsistent non-exhaustive pattern matching with if statements

Regex to return all subdomains from a given domain

Given a domain string like aaaa.bbbb.cccc.dddd I am trying to iterate over all of its subdomains i.e. aaaa.bbbb.cccc.dddd bbbb.cccc.dddd cccc.dddd dddd I thought this regex ((?:[a-zA-Z0-9]+\.)*)([a-zA-Z0-9]+)$ should do the trick (please ignore the fact, that I am only matching these characters [a-zA-Z0-9]), however it only matches the full string. How can I modify it to… Read More Regex to return all subdomains from a given domain