Casting Address field return nil

I was trying to cast input in address field but it always return nil. Any help would be appreciated.

transaction {
prepare(acct: AuthAccount)
{}
execute {
var someStruct: AnyStruct = 0x01
var address = someStruct as! Address
log(address)
} }
I want to validate that AnyStruct is Address or not

The value that you are setting as AnyStruct is not an address, so the casting will fail

You’ll need to do something like this:

var someAddress: Address = 0x01
var someStruct: AnyStruct = someAddress
var address = someStruct as! Address
log(address)

Does that work?

No @flowjosh . basically i am taking an input without knowing its type. and Cast that input on the basis of their type. somesstruct(input) could be wrong like an int, float or bool too. Main issue in the solution that someaddress has address datatype but in my case i am taking input directly AnyStruct and wanted to cast that input.
But thanks for your time

But what I am saying is that in your example, someStruct is not an address so that casting will always fail. If you want to see if it is an address or not, you need to use optional casting and check the result

var someStruct: AnyStruct = 0x01
var address = someStruct as? Address
if address == nil {
  // not an address
} else }
  // is an address
}